var fsjd=null;
var opts = window.opts;
var localPath=window.localPath;
var textEditor = angular
	.module('textEditor',['angularFileUpload'])
	.controller(
		'editorController',
		function($scope,$http,FileUploader,$compile, $sce) {
			var pathName=window.location.pathname.substring(1);
			var index=pathName.indexOf("/")+1;
			//后台路径前缀
			$scope.path="http://"+window.location.host+window.location.pathname.substring(0,index);
			//保存后的elementShow页面图片的路径前缀
			$scope.picPath=opts.pathSuffix+localPath;
			
			//图片集新增页面选中的图片标号
			$scope.imageClickIndex=null;
			//当前一次性上传图片个数
			$scope.currentImgIndex=0;
			//是否已经提示了超出5张了，用来判断防止多次弹框
			$scope.currentImgOutFlag=false;
			//图片集上传
			$scope.uploader = new FileUploader({
				url : $scope.path+'/common/file/weUpload?bookCode='+opts.bookCode+'&TYPE=Image',
				autoUpload:true,
				onProgressAll : function() {
					$scope.currentUploading=true;
				},
				onSuccessItem : function(item, response, status,
					headers) {
					if(response.success){
						if($scope.imageClickIndex==null){
							var imageJson={path:response.url,title:"",href:"",hrefType:"No",hrefNodeId:""};
							$scope.currentPic.imagesUrl.push(imageJson);
						}else{
							$scope.currentPic.imagesUrl[$scope.imageClickIndex].path=response.url;
						}
						
						$scope.currentUploading=false;
						
						
		        	}else{
		        		alert(response.msg);
		        		$scope.currentUploading=false;
		        	}
					$scope.imageClickIndex=null;
					$scope.currentImgIndex=0;
				}
			    });
			
			$scope.imageClickUpload=function(index){
				$scope.imageClickIndex=index;
				
			};
			//验证图片上传的格式
			$scope.uploader.filters
		    .push({
			name : 'imageFilter',
			fn : function(
				item /* {File|FileLikeObject} */,
				options) {
				
			    var type = '|'
				    + item.type.slice(item.type
					    .lastIndexOf('/') + 1)
				    + '|';
			    if('|jpg|png|jpeg|bmp|gif|'
					    .indexOf(type) == -1){
			    	alert("选择图片格式不支持！");
			    	return false;
			    }else{
			    	$scope.currentImgIndex=$scope.currentImgIndex+1;
					if(($scope.currentImgIndex>5||($scope.currentPic.imagesUrl.length+$scope.currentImgIndex)>5)&&$scope.imageClickIndex==null){
						if($scope.currentImgOutFlag){
							return false;
						}else{
							$scope.currentImgOutFlag=true;
							alert("图片集最多支持上传5张图片！");
							return false;
						}
						
					}else if($scope.imageClickIndex!=null&&(($scope.currentImgIndex>5||($scope.currentPic.imagesUrl.length+$scope.currentImgIndex)>6))){
						if($scope.currentImgOutFlag){
							return false;
						}else{
							$scope.currentImgOutFlag=true;
							alert("图片集最多支持上传5张图片！");
							return false;
						}
					}else{
						
						return true;
					}
			    	
			    }
			}
		    });
			
			
			$scope.imageClickIndex2=null;
			$scope.currentImgIndex2=0;
			$scope.currentImgOutFlag2=false;
			//图片集上传修改
			$scope.uploaderImg = new FileUploader({
				url : $scope.path+'/common/file/weUpload?bookCode='+opts.bookCode+'&TYPE=Image',
				autoUpload:true,
				onProgressAll : function() {
					$scope.currentUploading=true;
				},
				onSuccessItem : function(item, response, status,
					headers) {
					if(response.success){
						if($scope.imageClickIndex2==null){
							var imageJson={path:response.url,title:"",href:"",hrefType:"No",hrefNodeId:""};
							$scope.allElements[$scope.checkedItemId].imagesSrc.push(imageJson);
							$scope.currentUploading=false;
						}else{
							$scope.allElements[$scope.checkedItemId].imagesSrc[$scope.imageClickIndex2].path=response.url;
							$scope.currentUploading=false;
						}
						
		        	}else{
		        		alert(response.msg);
		        		$scope.currentUploading=false;
		        	}
					$scope.imageClickIndex2=null;
					$scope.currentImgIndex2=0;
				}
			    });
			
			$scope.imageClickUpload2=function(index){
				$scope.imageClickIndex2=index;
			};
			
			//验证图片上传的格式
			$scope.uploaderImg.filters
		    .push({
			name : 'imageFilter',
			fn : function(
				item /* {File|FileLikeObject} */,
				options) {
			    var type = '|'
				    + item.type.slice(item.type
					    .lastIndexOf('/') + 1)
				    + '|';
			    if('|jpg|png|jpeg|bmp|gif|'
					    .indexOf(type) == -1){
			    	alert("选择图片格式不支持！");
			    	return false;
			    }else{
			    	$scope.currentImgIndex2=$scope.currentImgIndex2+1;
					if(($scope.currentImgIndex2>5||($scope.allElements[$scope.checkedItemId].imagesSrc.length+$scope.currentImgIndex2)>5)&&$scope.imageClickIndex2==null){
						if($scope.currentImgOutFlag2){
							return false;
						}else{
							$scope.currentImgOutFlag2=true;
							alert("图片集最多支持上传5张图片！");
							return false;
						}
						
					}else if($scope.imageClickIndex2!=null&&(($scope.currentImgIndex2>5||($scope.allElements[$scope.checkedItemId].imagesSrc.length+$scope.currentImgIndex2)>6))){
						if($scope.currentImgOutFlag){
							return false;
						}else{
							$scope.currentImgOutFlag=true;
							alert("图片集最多支持上传5张图片！");
							return false;
						}
					}else{
						
						return true;
					}
			    }
			}
		    });
			
			///////////////视频////////////////////
			//视频上传
			$scope.uploaderVideo = new FileUploader({
				url : $scope.path+'/common/file/weUpload?bookCode='+opts.bookCode+'&TYPE=Video',
				autoUpload:true,
				onProgressAll : function() {
					$scope.currentUploading=true;
				},
				onSuccessItem : function(item, response, status,
					headers) {
					
					if(response.success){
						$scope.currentVideo.url=response.url;
						$scope.currentUploading=false;
		        	}else{
		        		alert(response.msg);
		        		$scope.currentUploading=false;
		        	}
				}
			    });
			
			$scope.uploaderVideo.filters
		    .push({
			name : 'imageFilter',
			fn : function(
				item /* {File|FileLikeObject} */,
				options) {
			    var type = '|'
				    + item.type.slice(item.type
					    .lastIndexOf('/') + 1)
				    + '|';
			    if('|mp4|MP4|'
					    .indexOf(type) == -1){
			    	alert("请上传mp4/MP4的视频格式！");
			    	return false;
			    }else{
			    	return true;
			    }
			}
		    });
			//视频图片上传
			$scope.uploaderVideoCover = new FileUploader({
				url : $scope.path+'/common/file/weUpload?bookCode='+opts.bookCode+'&TYPE=Image',
				autoUpload:true,
				onProgressAll : function() {
					$scope.currentUploading=true;;
				},
				onSuccessItem : function(item, response, status,
					headers) {
					
					if(response.success){
						$scope.currentVideo.coverImg=response.url;
						$scope.currentUploading=false;
		        	}else{
		        		alert(response.msg);
		        		$scope.currentUploading=false;
		        	}
				}
			    });
			
			//验证图片上传的格式
			$scope.uploaderVideoCover.filters
		    .push({
			name : 'imageFilter',
			fn : function(
				item /* {File|FileLikeObject} */,
				options) {
			    var type = '|'
				    + item.type.slice(item.type
					    .lastIndexOf('/') + 1)
				    + '|';
			    if('|jpg|png|jpeg|bmp|gif|'
					    .indexOf(type) == -1){
			    	alert("选择图片格式不支持！");
			    	return false;
			    }else{
			    	return true;
			    }
			}
		    });
			
			$scope.uploaderVideoChange = new FileUploader({
				url : $scope.path+'/common/file/weUpload?bookCode='+opts.bookCode+'&TYPE=Video',
				autoUpload:true,
				onProgressAll : function() {
					$scope.currentUploading=true;
				},
				onSuccessItem : function(item, response, status,
					headers) {
					if(response.success){
						$scope.allElements[$scope.checkedItemId].src=response.url;
						$scope.currentUploading=false;
		        	}else{
		        		alert(response.msg);
		        		$scope.currentUploading=false;
		        	}
				}
			    });
			//视频图片上传
			$scope.uploaderVideoCoverChange = new FileUploader({
				url : $scope.path+'/common/file/weUpload?bookCode='+opts.bookCode+'&TYPE=Image',
				autoUpload:true,
				onProgressAll : function() {
					$scope.currentUploading=true;
				},
				onSuccessItem : function(item, response, status,
					headers) {
					
					if(response.success){
						$scope.allElements[$scope.checkedItemId].coverImg=response.url;
						$scope.currentUploading=false;
		        	}else{
		        		alert(response.msg);
		        		$scope.currentUploading=false;
		        	}
				}
			    });
			
			//验证图片上传的格式
			$scope.uploaderVideoCoverChange.filters
		    .push({
			name : 'imageFilter',
			fn : function(
				item /* {File|FileLikeObject} */,
				options) {
			    var type = '|'
				    + item.type.slice(item.type
					    .lastIndexOf('/') + 1)
				    + '|';
			    if('|jpg|png|jpeg|bmp|gif|'
					    .indexOf(type) == -1){
			    	alert("选择图片格式不支持！");
			    	return false;
			    }else{
			    	return true;
			    }
			}
		    });
			//////////////////视频结束///////////////
			
			/////////////音频////////////////////
			//音频上传
			$scope.uploaderAudio = new FileUploader({
				url : $scope.path+'/common/file/weUpload?bookCode='+opts.bookCode+'&TYPE=Audio',
				autoUpload:true,
				onProgressAll : function() {
					$scope.currentUploading=true;
				},
				onSuccessItem : function(item, response, status,
					headers) {
					if(response.success){
						$scope.currentAudio.url=response.url;
						$scope.currentUploading=false;
						alert("上传成功");
		        	}else{
		        		alert(response.msg);
		        		$scope.currentUploading=false;
		        	}
				}
			    });
			
			$scope.uploaderAudioCover = new FileUploader({
				url : $scope.path+'/common/file/weUpload?bookCode='+opts.bookCode+'&TYPE=Image',
				autoUpload:true,
				onProgressAll : function() {
					$scope.currentUploading=true;
				},
				onSuccessItem : function(item, response, status,
					headers) {
					if(response.success){
						$scope.currentAudio.coverImg=response.url;
						$scope.currentUploading=false;
		        	}else{
		        		alert(response.msg);
		        		$scope.currentUploading=false;
		        	}
				}
			    });
			
			//验证图片上传的格式
			$scope.uploaderAudioCover.filters
		    .push({
			name : 'imageFilter',
			fn : function(
				item /* {File|FileLikeObject} */,
				options) {
			    var type = '|'
				    + item.type.slice(item.type
					    .lastIndexOf('/') + 1)
				    + '|';
			    if('|jpg|png|jpeg|bmp|gif|'
					    .indexOf(type) == -1){
			    	alert("选择图片格式不支持！");
			    	return false;
			    }else{
			    	return true;
			    }
			}
		    });
			$scope.uploaderAudioChange = new FileUploader({
				url : $scope.path+'/common/file/weUpload?bookCode='+opts.bookCode+'&TYPE=Audio' ,
				autoUpload:true,
				onProgressAll : function() {
					$scope.currentUploading=true;
				},
				onSuccessItem : function(item, response, status,
					headers) {
					
					if(response.success){
						$scope.allElements[$scope.checkedItemId].src=response.url;
						$scope.currentUploading=false;
		        	}else{
		        		alert(response.msg);
		        		$scope.currentUploading=false;
		        	}
				}
			    });
			
			$scope.uploaderAudioCoverChange = new FileUploader({
				url : $scope.path+'/common/file/weUpload?bookCode='+opts.bookCode+'&TYPE=Image',
				autoUpload:true,
				onProgressAll : function() {
					$scope.currentUploading=true;
				},
				onSuccessItem : function(item, response, status,
					headers) {
					
					if(response.success){
						$scope.allElements[$scope.checkedItemId].audioCoverImg=response.url;
						$scope.currentUploading=false;
		        	}else{
		        		alert(response.msg);
		        		$scope.currentUploading=false;
		        	}
				}
			    });
			
			//验证图片上传的格式
			$scope.uploaderAudioCoverChange.filters
		    .push({
			name : 'imageFilter',
			fn : function(
				item /* {File|FileLikeObject} */,
				options) {
			    var type = '|'
				    + item.type.slice(item.type
					    .lastIndexOf('/') + 1)
				    + '|';
			    if('|jpg|png|jpeg|bmp|gif|'
					    .indexOf(type) == -1){
			    	alert("选择图片格式不支持！");
			    	return false;
			    }else{
			    	return true;
			    }
			}
		    });
			
			
			
			$scope.uploaderPdf = new FileUploader({
				url : $scope.path+'/common/file/weUpload?bookCode='+opts.bookCode+'&TYPE=PDF' ,
				autoUpload:true,
				onProgressAll : function() {
					$scope.currentUploading=true;
				},
				onSuccessItem : function(item, response, status,
					headers) {
					
					if(response.success){
						$scope.currentDoc.url=response.url;
						$scope.currentUploading=false;
		        	}else{
		        		alert(response.msg);
		        		$scope.currentUploading=false;
		        	}
				}
			    });
			
			$scope.uploaderWord = new FileUploader({
				url : $scope.path+'/common/file/weUpload?bookCode='+opts.bookCode+'&TYPE=Word',
				autoUpload:true,
				onProgressAll : function() {
					$scope.currentUploading=true;
				},
				onSuccessItem : function(item, response, status,
					headers) {
					
					if(response.success){
						$scope.currentDoc.url=response.url;
						$scope.currentUploading=false;
		        	}else{
		        		alert(response.msg);
		        		$scope.currentUploading=false;
		        	}
				}
			    });
			$scope.uploaderOther = new FileUploader({
				url : $scope.path+'/common/file/weUpload?bookCode='+opts.bookCode+'&TYPE=Other',
				autoUpload:true,
				onProgressAll : function() {
					$scope.currentUploading=true;
				},
				onSuccessItem : function(item, response, status,
					headers) {
					
					if(response.success){
						$scope.currentDoc.url=response.url;
						$scope.currentUploading=false;
		        	}else{
		        		alert(response.msg);
		        		$scope.currentUploading=false;
		        	}
				}
			    });
			$scope.uploaderPdfChange = new FileUploader({
				url :$scope.path+'/common/file/weUpload?bookCode='+opts.bookCode+'&TYPE=PDF',
				autoUpload:true,
				onProgressAll : function() {
					$scope.currentUploading=true;
				},
				onSuccessItem : function(item, response, status,
					headers) {
					
					if(response.success){
						$scope.allElements[$scope.checkedItemId].src=response.url;
						$scope.currentUploading=false;
		        	}else{
		        		alert(response.msg);
		        		$scope.currentUploading=false;
		        	}
				}
			    });
			
			$scope.uploaderWordChange = new FileUploader({
				url : $scope.path+'/common/file/weUpload?bookCode='+opts.bookCode+'&TYPE=Word',
				autoUpload:true,
				onProgressAll : function() {
					$scope.currentUploading=true;
				},
				onSuccessItem : function(item, response, status,
					headers) {
					
					if(response.success){
						$scope.allElements[$scope.checkedItemId].src=response.url;
						$scope.currentUploading=false;
		        	}else{
		        		alert(response.msg);
		        		$scope.currentUploading=false;
		        	}
				}
			    });
			$scope.uploaderOtherChange = new FileUploader({
				url : $scope.path+'/common/file/weUpload?bookCode='+opts.bookCode+'&TYPE=Other',
				autoUpload:true,
				onProgressAll : function() {
					$scope.currentUploading=true;
				},
				onSuccessItem : function(item, response, status,
					headers) {
					
					if(response.success){
						$scope.allElements[$scope.checkedItemId].src=response.url;
						$scope.currentUploading=false;
		        	}else{
		        		alert(response.msg);
		        		$scope.currentUploading=false;
		        	}
				}
			    });
			
			
			
			//文本背景图片上传
			$scope.uploaderBgImage= new FileUploader({
				url : $scope.path+'/common/file/weUpload?bookCode='+opts.bookCode+'&TYPE=Image',
				autoUpload:true,
				onProgressAll : function() {
					$scope.currentUploading=true;;
				},
				onSuccessItem : function(item, response, status,
					headers) {
					
					if(response.success){
						$scope.allElements[$scope.checkedItemId].backgroundImage="url("+response.url+")";
						$scope.currentUploading=false;
		        	}else{
		        		alert(response.msg);
		        		$scope.currentUploading=false;
		        	}
				}
			    });
			
			//验证图片上传的格式
			$scope.uploaderBgImage.filters
		    .push({
			name : 'imageFilter',
			fn : function(
				item /* {File|FileLikeObject} */,
				options) {
			    var type = '|'
				    + item.type.slice(item.type
					    .lastIndexOf('/') + 1)
				    + '|';
			    if('|jpg|png|jpeg|bmp|gif|'
					    .indexOf(type) == -1){
			    	alert("选择图片格式不支持！");
			    	return false;
			    }else{
			    	return true;
			    }
			}
		    });
			
			//src里面路径转码
			$scope.trustSrc = function(src) {
		        return $sce.trustAsResourceUrl(src);
		      };
			fsjd=$scope;
			$scope.compile = $compile;
			$scope.currentVideo={
					url:"",
					coverImg:"",
					title:""
			};
			
			$scope.currentFontWeight=false;
			$scope.currentFontStyle=false;
			$scope.currentTextDecoration=false;
			$scope.currentUploading=false;
			$scope.currentAudio={
					url:"",
					content:"",
					coverImg:"",
					title:""
			};
			/**超链接*/
			$scope.currentUrl="";
			$scope.currentUrlType="No";
			$scope.currentUrlNodeId="";
			
			$scope.checkedItemId=null;
			$scope.currentPic={
					url:"",
					width:"100%",
					height:"auto",
					isNormalSize:"Y",
					isClickChange:"N",
					imageWidthLock:true,
					imagesUrl:[]
			};
			
			
			$scope.currentDoc={
					url:"",
					title:"",
					type:""
			};
			
			
			$scope.page={
					marginTop:'8',
					marginBottom:'8',
					marginLeft:'8',
					marginRight:'8'
			};
			$scope.pageStyle={
					marginTop:$scope.page.marginTop+"px",
					marginBottom:$scope.page.marginBottom+"px",
					marginLeft:$scope.page.marginLeft+"px",
					marginRight:$scope.page.marginRight+"px"
			};
			$scope.changeMargin=function(){
				$scope.pageStyle={
						marginTop:$scope.page.marginTop+"px",
						marginBottom:$scope.page.marginBottom+"px",
						marginLeft:$scope.page.marginLeft+"px",
						marginRight:$scope.page.marginRight+"px"
				};
			};
			
			 $scope.allElements=new Array();
			 getElementArr($scope);
			 $scope.index=1;
			 $scope.addFontStyle=false;
		    $scope.onLoad = function() {
		    	if(opts.json!=""&&opts.json!=null){
		    		var allElements=JSON.parse(opts.json);
		    		//var allElements=eval( "(" + opts.json+ ")" );//60上有测试错误【奇人奇事】雾霾终结者
		    		for(var i=0;i<allElements.content.length;i++){
		    			
		    			$scope.allElements[allElements.content[i].id]=allElements.content[i];
		    			if($scope.allElements[allElements.content[i].id].type=="audio"){
		    				$scope.allElements[allElements.content[i].id].audioContent=$scope.allElements[allElements.content[i].id].audioContent.replace(/<BR>/g,"\n");
		    				
		    			}
		    			if($scope.allElements[allElements.content[i].id].type=="content"){
		    				if(!$scope.allElements[allElements.content[i].id].hasOwnProperty("backgroundImage")){
		    					$scope.allElements[allElements.content[i].id].backgroundImage="url("+$scope.allElements[allElements.content[i].id].bgImage+")";
		    				}
		    				if($scope.allElements[allElements.content[i].id].backgroundImage=="url()"){
		    					$scope.allElements[allElements.content[i].id].backgroundImage="";
		    				}
		    				if(!$scope.allElements[allElements.content[i].id].hasOwnProperty("textIndent")){
		    					$scope.allElements[allElements.content[i].id].textIndent="";
		    				}
		    				if(!$scope.allElements[allElements.content[i].id].hasOwnProperty("lineHeight")){
		    					$scope.allElements[allElements.content[i].id].lineHeight="150%";
		    				}
		    				
		    			}
		    			if($scope.allElements[allElements.content[i].id].type=="title"){
		    				if(!$scope.allElements[allElements.content[i].id].hasOwnProperty("fontSizeFlag")){
		    					$scope.allElements[allElements.content[i].id].fontSizeFlag=$scope.allElements[allElements.content[i].id].fontSize;
		    					$scope.allElements[allElements.content[i].id].fontSize="";
		    				}
		    				
		    				
		    			}
		    			
		    			if($scope.allElements[allElements.content[i].id].type=="image"){
		    				if($scope.allElements[allElements.content[i].id].hasOwnProperty("imagesSrc")&&$scope.allElements[allElements.content[i].id].imagesSrc.length>0){
		    					for(var j=0;j<$scope.allElements[allElements.content[i].id].imagesSrc.length;j++){
		    						var image=$scope.allElements[allElements.content[i].id].imagesSrc[j];
		    						if(!image.hasOwnProperty("path")){
		    							$scope.allElements[allElements.content[i].id].imagesSrc[j].path="";
		    						}
		    						if(!image.hasOwnProperty("title")){
		    							$scope.allElements[allElements.content[i].id].imagesSrc[j].title="";
		    						}
		    						if(!image.hasOwnProperty("href")){
		    							$scope.allElements[allElements.content[i].id].imagesSrc[j].href="";
		    						}
		    						if(!image.hasOwnProperty("hrefType")){
		    							$scope.allElements[allElements.content[i].id].imagesSrc[j].hrefType="No";
		    						}
		    						if(!image.hasOwnProperty("hrefNodeId")){
		    							$scope.allElements[allElements.content[i].id].imagesSrc[j].hrefNodeId="";
		    						}
		    					}
		    				}
		    				
		    			}
		    			if($scope.allElements[allElements.content[i].id].hasOwnProperty("margin")){
	    					if(!$scope.allElements[allElements.content[i].id].hasOwnProperty("marginTopStyle")&&$scope.allElements[allElements.content[i].id].hasOwnProperty("marginTop")){
		    					$scope.allElements[allElements.content[i].id].marginTopStyle=$scope.allElements[allElements.content[i].id].marginTop;
		    				}
	    					if(!$scope.allElements[allElements.content[i].id].hasOwnProperty("marginTop")){
		    					$scope.allElements[allElements.content[i].id].marginTop='5px';
		    					$scope.allElements[allElements.content[i].id].marginTopStyle='5';
		    				}
	    					if(!$scope.allElements[allElements.content[i].id].hasOwnProperty("marginBottomStyle")&&$scope.allElements[allElements.content[i].id].hasOwnProperty("marginBottom")){
		    					$scope.allElements[allElements.content[i].id].marginBottomStyle=$scope.allElements[allElements.content[i].id].marginBottom;
		    				}
	    					if(!$scope.allElements[allElements.content[i].id].hasOwnProperty("marginBottom")){
		    					$scope.allElements[allElements.content[i].id].marginBottom='5px';
		    					$scope.allElements[allElements.content[i].id].marginBottomStyle='5';
		    				}
		    				
	    				}else{
	    					if(!$scope.allElements[allElements.content[i].id].hasOwnProperty("marginTopStyle")&&$scope.allElements[allElements.content[i].id].hasOwnProperty("marginTop")){
		    					$scope.allElements[allElements.content[i].id].marginTopStyle=$scope.allElements[allElements.content[i].id].marginTop;
		    				}
	    					if(!$scope.allElements[allElements.content[i].id].hasOwnProperty("marginTop")){
		    					$scope.allElements[allElements.content[i].id].marginTop='0px';
		    					$scope.allElements[allElements.content[i].id].marginTopStyle='0';
		    				}
	    					if(!$scope.allElements[allElements.content[i].id].hasOwnProperty("marginBottomStyle")&&$scope.allElements[allElements.content[i].id].hasOwnProperty("marginBottom")){
		    					$scope.allElements[allElements.content[i].id].marginBottomStyle=$scope.allElements[allElements.content[i].id].marginBottom;
		    				}
	    					if(!$scope.allElements[allElements.content[i].id].hasOwnProperty("marginBottom")){
		    					$scope.allElements[allElements.content[i].id].marginBottom='0px';
		    					$scope.allElements[allElements.content[i].id].marginBottomStyle='0';
		    				}
	    					
	    				}
		    			
		    		}
		    		if(allElements.hasOwnProperty("page")){
		    			$scope.page=allElements.page;
		    			$scope.pageStyle={
		    					marginTop:$scope.page.marginTop+"px",
		    					marginBottom:$scope.page.marginBottom+"px",
		    					marginLeft:$scope.page.marginLeft+"px",
		    					marginRight:$scope.page.marginRight+"px"
		    			};
		    		}else{
		    			$scope.page={
		    					marginTop:'8',
		    					marginBottom:'8',
		    					marginLeft:'8',
		    					marginRight:'8'
		    			};
		    			$scope.pageStyle={
		    					marginTop:$scope.page.marginTop+"px",
		    					marginBottom:$scope.page.marginBottom+"px",
		    					marginLeft:$scope.page.marginLeft+"px",
		    					marginRight:$scope.page.marginRight+"px"
		    			};
		    		}
		    		$scope.index=allElements.elementIndex;
		    		//$scope.allElements=JSON.parse(opts.json);
		    		
		    		getElementArr($scope);
		    		
		    		
		    	}
		    	
		    };

		    
		    $scope.addTitleFlag=false;
		    $scope.clickAddTitle=function(){
		    	$scope.addTitleFlag=true;
		    	$scope.setParamFlag=false;
		    };
		    
		    $scope.addMediaFlag=false;
		    $scope.clickAddMedia=function(){
		    	$scope.addMediaFlag=true;
		    	$scope.setParamFlag=false;
		    };
		    
		    $scope.changeItemMargin=function(){
		    	$scope.allElements[$scope.checkedItemId].marginTop=$scope.allElements[$scope.checkedItemId].marginTopStyle+"px";
		    	$scope.allElements[$scope.checkedItemId].marginBottom=$scope.allElements[$scope.checkedItemId].marginBottomStyle+"px";
		    };
		    
		    $scope.addTitle=function(flag){
		    	$scope.index ++;
		    	addItem={
		    			id:"title"+$scope.index,
		    			type:"title",
		    			content:"",
		    			fontSize:"",
		    			fontSizeFlag:flag+"",
		    			textAlign:"center",
		    			marginTop:'0px',
		    			marginBottom:'0px',
		    			marginTopStyle:'0',
		    			marginBottomStyle:'0',
		    			checked:true
		    	};
		    	$scope.allElements[addItem.id]=addItem;
		    	$scope.checkedItemId=addItem.id;
		    	$scope.clearCheck();
		    	getElementArr($scope);
		    	$scope.allElements[addItem.id].checked=true;
		    	$scope.addTitleFlag=false;
		    	$scope.setParamFlag=false;
		    };
		    $scope.addContent=function(){
		    	$scope.index ++;
		    	addItem={
		    			id:"content"+$scope.index,
		    			type:"content",
		    			content:"",
		    			fontSize:"12px",
		    			textAlign:"left",
		    			bgImage:"",
		    			backgroundImage:"",
		    			marginTop:'0px',
		    			marginBottom:'0px',
		    			marginTopStyle:'0',
		    			marginBottomStyle:'0',
		    			textIndent:"",
		    			lineHeight:'150%',
		    			checked:true
		    	};
		    	$scope.allElements[addItem.id]=addItem;
		    	$scope.checkedItemId=addItem.id;
		    	$scope.clearCheck();
		    	getElementArr($scope);
		    	$scope.allElements[addItem.id].checked=true;
		    	$scope.setParamFlag=false;
		    };
		    
		    $scope.addResourceContent=function(data){
		    	$scope.index ++;
		    	addItem={
		    			id:"content"+$scope.index,
		    			type:"content",
		    			content:data.content,
		    			fontSize:"12px",
		    			textAlign:"left",
		    			bgImage:"",
		    			backgroundImage:"",
		    			marginTop:'0px',
		    			marginBottom:'0px',
		    			marginTopStyle:'0',
		    			marginBottomStyle:'0',
		    			textIndent:"",
		    			lineHeight:'150%',
		    			checked:true
		    	};
		    	$scope.allElements[addItem.id]=addItem;
		    	$scope.checkedItemId=addItem.id;
		    	$scope.clearCheck();
		    	getElementArr($scope);
		    	$scope.allElements[addItem.id].checked=true;
		    	$scope.setParamFlag=false;
		    };
		   
		   
		   $scope.addImage=function(){
			   
			   $scope.uploader.clearQueue();
			   loadImageUpload($scope,$http);
			   $scope.currentPic={
						url:"",
						width:"100%",
						height:"auto",
						isNormalSize:"Y",
						isClickChange:"N",
						imageWidthLock:true,
						imagesUrl:[]
				};
			   $scope.currentImgIndex=0;
				$scope.currentImgOutFlag=false;
				$scope.setParamFlag=false;
				$scope.addMediaFlag=false;
		   };
		   
		   $scope.removeImg=function(index,flag){
			   if(flag){
				   $scope.allElements[$scope.checkedItemId].imagesSrc.splice(index,1);
				   $scope.imageClickIndex2=null;
				   $scope.currentImgIndex2=0;
			   }else{
				   $scope.currentPic.imagesUrl.splice(index,1);
				   $scope.imageClickIndex=null;
				   $scope.currentImgIndex=0;
			   }
			   
		   };
		   
		   $scope.saveImage=function(){
			   if($scope.currentPic.imagesUrl.length==""){
				   alert("请上传后保存");
				   return ;
			   }
			   $scope.index ++;
			   var width="100%";
			   if($("input[name='picSize']:checked").val()=="N"){
				   width=$scope.currentPic.width;
			   }
		    	addItem={
		    			id:"image"+$scope.index,
		    			type:"image",
		    			width:width,
		    			height:$scope.currentPic.height,
		    			content:"",
		    			textAlign:"center",
		    			imagesSrc:$scope.currentPic.imagesUrl,
		    			isNormalSize:$scope.currentPic.isNormalSize,
						imageWidthLock:$scope.currentPic.imageWidthLock,
		    			isClickChange:$scope.currentPic.isClickChange,
		    			marginTop:'0px',
		    			marginBottom:'0px',
		    			marginTopStyle:'0',
		    			marginBottomStyle:'0',
		    			checked:true
		    	};
		    	$scope.allElements[addItem.id]=addItem;
		    	$scope.checkedItemId=addItem.id;
		    	$scope.clearCheck();
		    	getElementArr($scope);
		    	$scope.allElements[addItem.id].checked=true;
		    	
		    	$('#imageModal').modal('hide');
		    	$scope.currentImgIndex=0;
				$scope.currentImgOutFlag=false;
				$scope.setParamFlag=false;
				$scope.addMediaFlag=false;
		   };
		   
		   $scope.saveResourceImage=function(data){
			   $scope.index ++;
			   var width="100%";
		    	addItem={
		    			id:"image"+$scope.index,
		    			type:"image",
		    			width:width,
		    			height:'auto',
		    			content:"",
		    			textAlign:"center",
		    			imagesSrc:data.imagesUrl,
		    			isNormalSize:'Y',
						imageWidthLock:true,
		    			isClickChange:'N',
		    			marginTop:'0px',
		    			marginBottom:'0px',
		    			marginTopStyle:'0',
		    			marginBottomStyle:'0',
		    			checked:true
		    	};
		    	$scope.allElements[addItem.id]=addItem;
		    	$scope.checkedItemId=addItem.id;
		    	$scope.clearCheck();
		    	getElementArr($scope);
		    	$scope.allElements[addItem.id].checked=true;
				$scope.setParamFlag=false;
				$scope.onPageClick();
		   };
		   
		   
		   
		   $scope.addVideo=function(){
			   $scope.uploaderVideo.clearQueue();
			   loadVideoUpload($scope,$http);
			   $scope.currentVideo={
						url:"",
						coverImg:"",
						title:""
				};
			   $scope.setParamFlag=false;
			   $scope.addMediaFlag=false;
		   };
		   
		  
		   
		   $scope.saveVideo=function(){
			   if($scope.currentVideo.url==""){
				   alert("请上传后保存");
				   return ;
			   }
			   $scope.index ++;
		    	addItem={
		    			id:"video"+$scope.index,
		    			type:"video",
		    			src:$scope.currentVideo.url,
		    			gSrc:"",
		    			content:"",
		    			videoTitle:$scope.currentVideo.title,
		    			coverImg:$scope.currentVideo.coverImg,
		    			marginTop:'0px',
		    			marginBottom:'0px',
		    			marginTopStyle:'0',
		    			marginBottomStyle:'0',
		    			checked:true
		    	};
		    	$scope.allElements[addItem.id]=addItem;
		    	$scope.checkedItemId=addItem.id;
		    	$scope.clearCheck();
		    	getElementArr($scope);
		    	$scope.allElements[addItem.id].checked=true;
		    	$('#videoModal').modal('hide');
		    	$scope.setParamFlag=false;
		    	$scope.addMediaFlag=false;
		   };
		   
		   $scope.saveResourceVideo=function(data){
			   $scope.index ++;
		    	addItem={
		    			id:"video"+$scope.index,
		    			type:"video",
		    			src:data.path,
		    			gSrc:"",
		    			content:"",
		    			videoTitle:data.title,
		    			coverImg:data.coverImg,
		    			marginTop:'0px',
		    			marginBottom:'0px',
		    			marginTopStyle:'0',
		    			marginBottomStyle:'0',
		    			checked:true
		    	};
		    	$scope.allElements[addItem.id]=addItem;
		    	$scope.checkedItemId=addItem.id;
		    	$scope.clearCheck();
		    	getElementArr($scope);
		    	$scope.allElements[addItem.id].checked=true;
		    	$scope.setParamFlag=false;
		   };
		   
		   $scope.addAudio=function(){
			   $scope.uploaderAudio.clearQueue();
			   loadAudioUpload($scope,$http);
			   $scope.currentAudio={
						url:"",
						content:"",
						coverImg:"",
						title:""
				};
			   $scope.setParamFlag=false;
			   $scope.addMediaFlag=false;
		   };
		   $scope.changeAudioContentEvent=function(obj){
				 $scope.currentAudio.content=obj.currentAudioContent;  
			};
			
			$scope.changeAudioTitleEvent=function(obj){
				$scope.currentAudio.title=obj.currentAudio.title;
			};
		   $scope.saveAudio=function(){
			   if($scope.currentAudio.url==""){
				   alert("请上传后保存");
				   return ;
			   }
			   $scope.index ++;
		    	addItem={
		    			id:"audio"+$scope.index,
		    			type:"audio",
		    			/*width:"100%",
		    			height:"30px",*/
		    			src:$scope.currentAudio.url,
		    			//hasAudioContent:$scope.currentAudioHasContent,
		    			audioContent:$scope.currentAudio.content,
		    			audioTitle:$scope.currentAudio.title,
		    			audioCoverImg:$scope.currentAudio.coverImg,
		    			marginTop:'0px',
		    			marginBottom:'0px',
		    			marginTopStyle:'0',
		    			marginBottomStyle:'0',
		    			checked:true
		    	};
		    	$scope.allElements[addItem.id]=addItem;
		    	$scope.checkedItemId=addItem.id;
		    	$scope.clearCheck();
		    	getElementArr($scope);
		    	$scope.allElements[addItem.id].checked=true;
		    	$('#audioModal').modal('hide');
		    	$scope.setParamFlag=false;
		    	$scope.addMediaFlag=false;
		   };
		   
		   $scope.saveResourceAudio=function(data){
			   $scope.index ++;
		    	addItem={
		    			id:"audio"+$scope.index,
		    			type:"audio",
		    			src:data.path,
		    			audioContent:data.content,
		    			audioTitle:data.title,
		    			audioCoverImg:data.coverImg,
		    			marginTop:'0px',
		    			marginBottom:'0px',
		    			marginTopStyle:'0',
		    			marginBottomStyle:'0',
		    			checked:true
		    	};
		    	$scope.allElements[addItem.id]=addItem;
		    	$scope.checkedItemId=addItem.id;
		    	$scope.clearCheck();
		    	getElementArr($scope);
		    	$scope.allElements[addItem.id].checked=true;
		    	$scope.setParamFlag=false;
		   };
		   
		   
		   $scope.addDocFlag=false;
		   $scope.addDoc=function(){
			   $scope.addDocFlag=true; 
			   $scope.setParamFlag=false;
		   };
		   
		   $scope.addPdf=function(){
			   $scope.uploaderPdf.clearQueue();
			   $scope.onPageClick();
			   loadPdfUpload($scope,$http);
			   $scope.currentDoc={
						url:"",
						title:"",
						type:"pdf"
						
				};
			   $scope.setParamFlag=false;
		   };
		   
		   $scope.savePdf=function(){
			   if($scope.currentDoc.url==""){
				   alert("请上传后保存");
				   return ;
			   }
			   $scope.index ++;
		    	addItem={
		    			id:"pdf"+$scope.index,
		    			type:"pdf",
		    			src:$scope.currentDoc.url,
		    			title:$scope.currentDoc.title,
		    			marginTop:'0px',
		    			marginBottom:'0px',
		    			marginTopStyle:'0',
		    			marginBottomStyle:'0',
		    			checked:true
		    	};
		    	$scope.allElements[addItem.id]=addItem;
		    	$scope.checkedItemId=addItem.id;
		    	$scope.clearCheck();
		    	getElementArr($scope);
		    	$scope.allElements[addItem.id].checked=true;
		    	$('#pdfModal').modal('hide');
		    	$scope.setParamFlag=false;
		   };
		   
		   $scope.saveResourcePdf=function(data){
			   $scope.index ++;
		    	addItem={
		    			id:"pdf"+$scope.index,
		    			type:"pdf",
		    			src:data.path,
		    			title:data.title,
		    			marginTop:'0px',
		    			marginBottom:'0px',
		    			marginTopStyle:'0',
		    			marginBottomStyle:'0',
		    			checked:true
		    	};
		    	$scope.allElements[addItem.id]=addItem;
		    	$scope.checkedItemId=addItem.id;
		    	$scope.clearCheck();
		    	getElementArr($scope);
		    	$scope.allElements[addItem.id].checked=true;
		    	$scope.setParamFlag=false;
		   };
		   $scope.addWord=function(){
			   $scope.uploaderWord.clearQueue();
			   $scope.onPageClick();
			   loadWordUpload($scope,$http);
			   $scope.currentDoc={
						url:"",
						title:"",
						type:"word"
						
				};
			   $scope.setParamFlag=false;
		   };
		   
		   $scope.saveWord=function(){
			   if($scope.currentDoc.url==""){
				   alert("请上传后保存");
				   return ;
			   }
			   $scope.index ++;
		    	addItem={
		    			id:"word"+$scope.index,
		    			type:"word",
		    			src:$scope.currentDoc.url,
		    			title:$scope.currentDoc.title,
		    			marginTop:'0px',
		    			marginBottom:'0px',
		    			marginTopStyle:'0',
		    			marginBottomStyle:'0',
		    			checked:true
		    	};
		    	$scope.allElements[addItem.id]=addItem;
		    	$scope.checkedItemId=addItem.id;
		    	$scope.clearCheck();
		    	getElementArr($scope);
		    	$scope.allElements[addItem.id].checked=true;
		    	$('#wordModal').modal('hide');
		    	$scope.setParamFlag=false;
		   };
		   
		   $scope.saveResourceWord=function(data){
			   $scope.index ++;
		    	addItem={
		    			id:"word"+$scope.index,
		    			type:"word",
		    			src:data.path,
		    			title:data.title,
		    			marginTop:'0px',
		    			marginBottom:'0px',
		    			marginTopStyle:'0',
		    			marginBottomStyle:'0',
		    			checked:true
		    	};
		    	$scope.allElements[addItem.id]=addItem;
		    	$scope.checkedItemId=addItem.id;
		    	$scope.clearCheck();
		    	getElementArr($scope);
		    	$scope.setParamFlag=false;
		   };
		   
		   $scope.addOther=function(){
			   $scope.uploaderOther.clearQueue();
			   $scope.onPageClick();
			   loadOtherUpload($scope,$http);
			   $scope.currentDoc={
						url:"",
						title:"",
						type:"accessory"
						
				};
			   $scope.setParamFlag=false;
		   };
		   
		   $scope.saveOther=function(){
			   if($scope.currentDoc.url==""){
				   alert("请上传后保存");
				   return ;
			   }
			   $scope.index ++;
		    	addItem={
		    			id:"accessory"+$scope.index,
		    			type:"accessory",
		    			src:$scope.currentDoc.url,
		    			title:$scope.currentDoc.title,
		    			marginTop:'0px',
		    			marginBottom:'0px',
		    			marginTopStyle:'0',
		    			marginBottomStyle:'0',
		    			checked:true
		    	};
		    	$scope.allElements[addItem.id]=addItem;
		    	$scope.checkedItemId=addItem.id;
		    	$scope.clearCheck();
		    	getElementArr($scope);
		    	$scope.allElements[addItem.id].checked=true;
		    	$('#otherModal').modal('hide');
		    	$scope.setParamFlag=false;
		   };
		   
		   $scope.saveResourceOther=function(data){
			   $scope.index ++;
		    	addItem={
		    			id:"accessory"+$scope.index,
		    			type:"accessory",
		    			src:data.path,
		    			title:data.title,
		    			marginTop:'0px',
		    			marginBottom:'0px',
		    			marginTopStyle:'0',
		    			marginBottomStyle:'0',
		    			checked:true
		    	};
		    	$scope.allElements[addItem.id]=addItem;
		    	$scope.checkedItemId=addItem.id;
		    	$scope.clearCheck();
		    	getElementArr($scope);
		    	$scope.allElements[addItem.id].checked=true;
		    	$('#otherModal').modal('hide');
		    	$scope.setParamFlag=false;
		   };
		   
		   
		   $scope.showResource=function(){
			   $scope.onPageClick();
			   loadResource($scope,$http);
			   $scope.setParamFlag=false;
		   };
		   
		   
		   $scope.deleteElement=function(ev,itemId){
			   delete $scope.allElements[itemId];
			   $scope.onPageClick();
			   getElementArr($scope);
			   
		   };
		   
		   $scope.fontColorChange=function(chooseColor,isChangeFlag){
			   var text=window.getSelection?window.getSelection().toString():(document.getSelection?document.getSelection():(document.selection?document.selection.createRange().text:""));
				 if(text!=""){
					 var contentChild=new Array();
					 if(window.getSelection().anchorNode.parentNode.tagName=="A"
						 ||window.getSelection().anchorNode.parentNode.tagName=="SPAN"){
						 contentChild=window.getSelection().anchorNode.parentNode.parentNode.childNodes;
					 }else{
						 contentChild=window.getSelection().anchorNode.parentNode.childNodes;
					 }
					 
					 var star = window.getSelection().anchorOffset;
		             var end = window.getSelection().focusOffset;
					//ie浏览器，把起始点为最前面的，会获取为外面父节点
			        	if(window.getSelection().anchorNode.tagName=="P"
			        		||window.getSelection().anchorNode.tagName=="H1"
			        			||window.getSelection().anchorNode.tagName=="H2"||window.getSelection().anchorNode.tagName=="H3"){
			        		contentChild=window.getSelection().anchorNode.childNodes;
			        	}
					 var selectAnchorNode = window.getSelection().anchorNode;
		             if(window.getSelection().anchorNode.parentNode.tagName=="A"
		            	 ||window.getSelection().anchorNode.parentNode.tagName=="SPAN"){
		                selectAnchorNode = window.getSelection().anchorNode.parentNode;
		             }
		             if((window.getSelection().anchorNode.tagName=="BR")&&window.getSelection().anchorOffset==0){
		            	 selectAnchorNode=window.getSelection().anchorNode.nextElementSibling;
		             }
		             if((window.getSelection().focusNode.tagName=="BR")&&window.getSelection().focusOffset==0){
		            	 selectAnchorNode=window.getSelection().focusNode.previousElementSibling;
		             }
		             //ie浏览器，把起始点为最前面的，会获取为外面父节点
			        	if((window.getSelection().anchorNode.tagName=="P"
			        		||window.getSelection().anchorNode.tagName=="H1"
			        			||window.getSelection().anchorNode.tagName=="H2"||window.getSelection().anchorNode.tagName=="H3")&&window.getSelection().anchorOffset==0){
			        		selectAnchorNode=contentChild[0];
			        		star=0;
			        	}
			        	//ie浏览器，把起始点为最前面的，会获取为外面父节点
			        	if((window.getSelection().anchorNode.tagName=="P"
			        		||window.getSelection().anchorNode.tagName=="H1"
			        			||window.getSelection().anchorNode.tagName=="H2"||window.getSelection().anchorNode.tagName=="H3")&&window.getSelection().anchorOffset!=0){
			        		selectAnchorNode=contentChild[contentChild.length-1];
			        		end=contentChild[contentChild.length-1].textContent.length;
			        	}
			        	
		             var selectFocusNode = window.getSelection().focusNode;
		             if(window.getSelection().focusNode.parentNode.tagName=="A"
		            	 ||window.getSelection().focusNode.parentNode.tagName=="SPAN"){
		                selectFocusNode = window.getSelection().focusNode.parentNode;
		             }
	                	//ie浏览器，把结束点为最后面的，会获取为外面父节点
				        if((window.getSelection().focusNode.tagName=="P"
				        		||window.getSelection().focusNode.tagName=="H1"
				        			||window.getSelection().focusNode.tagName=="H2"||window.getSelection().focusNode.tagName=="H3")&&window.getSelection().focusOffset==0){
				        	selectFocusNode=contentChild[0];
				        	star=0;
				        }
				      //ie浏览器，把结束点为最后面的，会获取为外面父节点
				        if((window.getSelection().focusNode.tagName=="P"
				        		||window.getSelection().focusNode.tagName=="H1"
				        			||window.getSelection().focusNode.tagName=="H2"||window.getSelection().focusNode.tagName=="H3")&&window.getSelection().focusOffset!=0){
				        	selectFocusNode=contentChild[contentChild.length-1];
				        	end=contentChild[contentChild.length-1].textContent.length;
				        }
		             var starNode=0;
		             var endNode=0;
		             
					 for(var i=0;i<contentChild.length;i++){
						 if(selectAnchorNode==contentChild[i]){
							 starNode = i;
						 }
						 if(selectFocusNode==contentChild[i]){
							 endNode = i;
						 }
		              }
					 
					 if(starNode>endNode){
						 var t=endNode;
						 endNode=starNode;
						 starNode=t; 
						 var s=end;
						 end=star;
						 star=s;
						 var f=selectAnchorNode;
						 selectAnchorNode=selectFocusNode;
						 selectFocusNode=f;
					 }
					 
					 if(starNode==endNode&&star>end){
						 var s=end;
						 end=star;
						 star=s;
					 }
					 
					 //当选中的是同一块,没有样式的
					 if((starNode==endNode&&selectAnchorNode.tagName!="A")
							 &&(starNode==endNode&&selectAnchorNode.tagName!="SPAN")){
						 
						 var stringToStartText="";
						 for(var i=0;i<starNode;i++){
							 if(contentChild[i].tagName=="SPAN"&&contentChild[i].textContent==""){
							 		
							 }else if(contentChild[i].tagName=="BR"){
								 stringToStartText=stringToStartText+contentChild[i].outerHTML;
							 }else{
								 if(contentChild[i].length){
									 stringToStartText=stringToStartText+contentChild[i].textContent;
						 		}else{
						 			stringToStartText=stringToStartText+contentChild[i].outerHTML;
						 		}
							 }
						 }
						 var stringToEndText="";
						 if(endNode!=(contentChild.length-1)){
							 for(var i=(endNode+1);i<contentChild.length;i++){
								 if(contentChild[i].tagName=="SPAN"&&contentChild[i].textContent==""){
								 		
								 }else if(contentChild[i].tagName=="BR"){
									 stringToEndText=stringToEndText+contentChild[i].outerHTML;
								 }else{
									 if(contentChild[i].length){
										 stringToEndText=stringToEndText+contentChild[i].textContent;
							 		}else{
							 			stringToEndText=stringToEndText+contentChild[i].outerHTML;
							 		}
								 }
								 
							 }
						 } 
						 var startText=window.getSelection().anchorNode.textContent.substring(0,star);
						 var endText=window.getSelection().focusNode.textContent.substring(end);
						 var centerText="<span style='color:"+chooseColor+";'>"+text+"</span>";
						 $scope.allElements[$scope.checkedItemId].content = stringToStartText+startText + centerText+endText+stringToEndText;
						
						 return ;
					 }
					 
					 
					 
					 
					 var stringToStart="";
					 for(var i=0;i<starNode;i++){
						 if(contentChild[i].tagName=="SPAN"&&contentChild[i].textContent==""){
						 		
						 }else if(contentChild[i].tagName=="BR"){
							 stringToStart=stringToStart+contentChild[i].outerHTML;
						 }else{
							 if(contentChild[i].length){
								 stringToStart=stringToStart+contentChild[i].textContent;
					 		}else{
					 			stringToStart=stringToStart+contentChild[i].outerHTML;
					 		}
						 }
					 }
					 var stringToEnd="";
					 if(endNode!=(contentChild.length-1)){
						 for(var i=(endNode+1);i<contentChild.length;i++){
							 if(contentChild[i].tagName=="SPAN"&&contentChild[i].textContent==""){
							 		
							 }else if(contentChild[i].tagName=="BR"){
								 stringToEnd=stringToEnd+contentChild[i].outerHTML;
							 }else{
								 if(contentChild[i].length){
									 stringToEnd=stringToEnd+contentChild[i].textContent;
						 		}else{
						 			stringToEnd=stringToEnd+contentChild[i].outerHTML;
						 		}
							 }
							
							 
						 }
					 }
					 var startA="";
					 if(selectAnchorNode.tagName=="A"){
						 if(star!=0&&selectAnchorNode.textContent.substring(0,star)!=""){
							 if(selectAnchorNode.className.indexOf("inCode")>0){
								 var styleStr=$scope.styleStr(selectAnchorNode);
             					if(styleStr!=""){
             						startA="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
             					}else{
             						startA="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
             					}
								 
							 }else if(selectAnchorNode.className.indexOf("outCode")>0){
								 var styleStr=$scope.styleStr(selectAnchorNode);
								 if(styleStr!=""){
									 startA="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
								 }else{
									 startA="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
								 }
								 
							 }else{
								 var styleStr=$scope.styleStr(selectAnchorNode);
								 if(styleStr!=""){
									 startA="<a href='"+selectAnchorNode.href+"' style='"+styleStr+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
								 }else{
									 startA="<a href='"+selectAnchorNode.href+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
								 }
								 
							 }
							 
							 
						 }
					 }else if(selectAnchorNode.tagName=="SPAN"){
						 if(star!=0&&selectAnchorNode.textContent.substring(0,star)!=""){
							 var styleStr=$scope.styleStr(selectAnchorNode);
          					if(styleStr!=""){
          						startA="<span style='"+styleStr+"'>"+selectAnchorNode.textContent.substring(0,star)+"</span>";
          					}else{
          						startA="<span>"+selectAnchorNode.textContent.substring(0,star)+"</span>";
          					}
							 
						 }
					 }else{
						 startA=selectAnchorNode.textContent.substring(0,star);
					 }
					 var endA="";
					 if(selectFocusNode.tagName=="A"){
						 if(end!=selectFocusNode.textContent.length&&selectFocusNode.textContent.substring(end)!=""){
							 if(selectFocusNode.className.indexOf("inCode")>0){
								 var styleStr=$scope.styleStr(selectFocusNode);
		          					if(styleStr!=""){
		          						endA="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"' style='"+styleStr+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
		          					}else{
		          						endA="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
		          					}
								 
							 }else if(selectFocusNode.className.indexOf("outCode")>0){
								 var styleStr=$scope.styleStr(selectFocusNode);
								 if(styleStr!=""){
									 endA="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"' style='"+styleStr+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
								 }else{
									 endA="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
								 }
								 
							 }else{
								 var styleStr=$scope.styleStr(selectFocusNode);
								 if(styleStr!=""){
									 endA="<a href='"+selectFocusNode.href+"' style='"+styleStr+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
								 }else{
									 endA="<a href='"+selectFocusNode.href+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
								 }
								 
							 }
							 
						 }
					 }else if(selectFocusNode.tagName=="SPAN"&&selectFocusNode.textContent.substring(end)!=""){
						 if(end!=selectFocusNode.textContent.length){
							 var styleStr=$scope.styleStr(selectFocusNode);
							 if(styleStr!=""){
								 endA="<span style='"+styleStr+"'>"+selectFocusNode.textContent.substring(end)+"</span>";
							 }else{
								 endA="<span>"+selectFocusNode.textContent.substring(end)+"</span>";
							 }
							 
						 }
					 }else{
						 endA=selectFocusNode.textContent.substring(end);
					 }
					 
					 if(starNode==endNode){
						 if(selectAnchorNode.tagName=="A"){
							 if(isChangeFlag){
								 
								 var styleStr=$scope.styleChange(selectAnchorNode,"color");
								 text="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"color:"+chooseColor+";'>"+text+"</a>";
							 }else{
								 var styleStr=$scope.styleChange(selectAnchorNode,"color");
								 text="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"color:"+chooseColor+";'>"+text+"</a>";
							 }
							 $scope.allElements[$scope.checkedItemId].content = stringToStart + startA+text+endA + stringToEnd ;
							 
						 }else if(selectAnchorNode.tagName=="SPAN"){
							 if(isChangeFlag){
								 var styleStr=$scope.styleChange(selectAnchorNode,"color");
								 text="<span style='"+styleStr+"color:"+chooseColor+";'>"+text+"</span>";
							 }else{
								 var styleStr=$scope.styleChange(selectAnchorNode,"color");
								 text="<span style='"+styleStr+"color:"+chooseColor+";'>"+text+"</span>";
							 }
							 $scope.allElements[$scope.checkedItemId].content = stringToStart + startA+text+endA + stringToEnd ;
							
						 }else{
							 text="<span style='color:"+chooseColor+";'>"+text+"</span>";
							 $scope.allElements[$scope.checkedItemId].content = stringToStart + startA+text+endA + stringToEnd ;
							 
						 }
						 
					 }else{
						 var startText="";
						 if(selectAnchorNode.tagName=="A"&&selectAnchorNode.textContent.substring(star)!=""){
							 if(isChangeFlag){
								 var styleStr=$scope.styleChange(selectAnchorNode,"color");
								 startText="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"color:"+chooseColor+";'>"+selectAnchorNode.textContent.substring(star)+"</a>";
							 }else{
								 var styleStr=$scope.styleChange(selectAnchorNode,"color");
								 startText="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"color:"+chooseColor+";'>"+selectAnchorNode.textContent.substring(star)+"</a>";
							 }
						 }else if(selectAnchorNode.tagName=="SPAN"&&selectAnchorNode.textContent.substring(star)!=""){
							 if(isChangeFlag){
								 var styleStr=$scope.styleChange(selectAnchorNode,"color");
								 startText="<span style='"+styleStr+"color:"+chooseColor+";'>"+selectAnchorNode.textContent.substring(star)+"</span>";
							 }else{
								 var styleStr=$scope.styleChange(selectAnchorNode,"color");
								 startText="<span style='"+styleStr+"color:"+chooseColor+";'>"+selectAnchorNode.textContent.substring(star)+"</span>";
							 }
						 }else{
							 if(selectAnchorNode.textContent.substring(star)!=""){
								 if(isChangeFlag){
									 startText=selectAnchorNode.textContent.substring(star); 
								 }else{
									 startText="<span style='color:"+chooseColor+";'>"+selectAnchorNode.textContent.substring(star)+"</span>";
								 }
								 
							 }
							 
						 }
						 
						 var endText="";
						 if(selectFocusNode.tagName=="A"&&selectFocusNode.textContent.substring(0,end)!=""){
							 if(isChangeFlag){
								 var styleStr=$scope.styleChange(selectFocusNode,"color");
								 endText="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"' style='"+styleStr+"color:"+chooseColor+";'>"+selectFocusNode.textContent.substring(0,end)+"</a>";
							 }else{
								 var styleStr=$scope.styleChange(selectFocusNode,"color");
								 endText="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"' style='"+styleStr+"color:"+chooseColor+";'>"+selectFocusNode.textContent.substring(0,end)+"</a>";
							 } 
							
						 }else if(selectFocusNode.tagName=="SPAN"&&selectFocusNode.textContent.substring(0,end)!=""){
							 if(isChangeFlag){
								 var styleStr=$scope.styleChange(selectFocusNode,"color");
								 endText="<span style='"+styleStr+"color:"+chooseColor+";'>"+selectFocusNode.textContent.substring(0,end)+"</span>";
							 }else{
								 var styleStr=$scope.styleChange(selectFocusNode,"color");
								 endText="<span style='"+styleStr+"color:"+chooseColor+";'>"+selectFocusNode.textContent.substring(0,end)+"</span>";
							 } 
						 }else{
							 if(selectFocusNode.textContent.substring(0,end)!=""){
								 if(isChangeFlag){
									 endText=selectFocusNode.textContent.substring(0,end);
								 }else{
									 endText="<span style='color:"+chooseColor+";'>"+selectFocusNode.textContent.substring(0,end)+"</span>";
								 }
							 }
							 
							 
						 }
						 var centerText="";
							 for(var i=starNode+1;i<endNode;i++){
								/* if(contentChild[i].textContent!=""){*/
								 if(contentChild[i].tagName=="SPAN"&&contentChild[i].textContent==""){
								 		
								 }else if(contentChild[i].tagName=="BR"){
									 centerText=centerText+contentChild[i].outerHTML;
								 }else{
									 if(contentChild[i].length){
										 if(isChangeFlag){
											
											 centerText=centerText+contentChild[i].textContent;
										 }else{
											
											 centerText=centerText+"<span style='color:"+chooseColor+";'>"+contentChild[i].textContent+"</span>";
										 }
										 
							 		}else{
							 			if(isChangeFlag){
											 contentChild[i].style.color=chooseColor;
										 }else{
											 contentChild[i].style.color=chooseColor;
										 }
							 			centerText=centerText+contentChild[i].outerHTML;
							 		}
								 }
								 
									 
								 /*}*/
								 
							 }
							 $scope.allElements[$scope.checkedItemId].content = stringToStart + startA+startText+centerText+endText+endA + stringToEnd ; 
					 }	
				 } 
				 window.getSelection().removeAllRanges();
				
		   };
		   
		   
		   $scope.styleChange=function(content,styleItem){
			   var styleStr="";
				if(content.style.fontSize!=""&&styleItem!="fontSize"){
					styleStr=styleStr+"font-size:"+content.style.fontSize+";";
				}
				if(content.style.fontWeight!=""&&styleItem!="fontWeight"){
					styleStr=styleStr+"font-weight:"+content.style.fontWeight+";";
				}
				if(content.style.fontStyle!=""&&styleItem!="fontStyle"){
					styleStr=styleStr+"font-style:"+content.style.fontStyle+";";
				}
				if(content.style.textDecoration!=""&&styleItem!="textDecoration"){
					styleStr=styleStr+"text-decoration:"+content.style.textDecoration+";";
				}
				if(content.style.color!=""&&styleItem!="color"){
					styleStr=styleStr+"color:"+content.style.color+";";
				}
				if(content.style.backgroundColor!=""&&styleItem!="backgroundColor"){
					styleStr=styleStr+"background-color:"+content.style.backgroundColor+";";
				}
				return styleStr;
		   };
		   
		   
		   $scope.fontBgColorChange=function(chooseColor,isChangeFlag){
			   var text=window.getSelection?window.getSelection().toString():(document.getSelection?document.getSelection():(document.selection?document.selection.createRange().text:""));
				 if(text!=""){
					 var contentChild=new Array();
					 if(window.getSelection().anchorNode.parentNode.tagName=="A"
						 ||window.getSelection().anchorNode.parentNode.tagName=="SPAN"){
						 contentChild=window.getSelection().anchorNode.parentNode.parentNode.childNodes;
					 }else{
						 contentChild=window.getSelection().anchorNode.parentNode.childNodes;
					 }
					 var star = window.getSelection().anchorOffset;
		             var end = window.getSelection().focusOffset;
					//ie浏览器，把起始点为最前面的，会获取为外面父节点
			        	if(window.getSelection().anchorNode.tagName=="P"
			        		||window.getSelection().anchorNode.tagName=="H1"
			        			||window.getSelection().anchorNode.tagName=="H2"||window.getSelection().anchorNode.tagName=="H3"){
			        		contentChild=window.getSelection().anchorNode.childNodes;
			        	}
					 var selectAnchorNode = window.getSelection().anchorNode;
		             if(window.getSelection().anchorNode.parentNode.tagName=="A"
		            	 ||window.getSelection().anchorNode.parentNode.tagName=="SPAN"){
		                selectAnchorNode = window.getSelection().anchorNode.parentNode;
		             }
		           //ie浏览器，把起始点为最前面的，会获取为外面父节点
			        	if((window.getSelection().anchorNode.tagName=="P"
			        		||window.getSelection().anchorNode.tagName=="H1"
			        			||window.getSelection().anchorNode.tagName=="H2"||window.getSelection().anchorNode.tagName=="H3")&&window.getSelection().anchorOffset==0){
			        		selectAnchorNode=contentChild[0];
			        		star=0;
			        	}
			        	//ie浏览器，把起始点为最前面的，会获取为外面父节点
			        	if((window.getSelection().anchorNode.tagName=="P"
			        		||window.getSelection().anchorNode.tagName=="H1"
			        			||window.getSelection().anchorNode.tagName=="H2"||window.getSelection().anchorNode.tagName=="H3")&&window.getSelection().anchorOffset!=0){
			        		selectAnchorNode=contentChild[contentChild.length-1];
			        		end=contentChild[contentChild.length-1].textContent.length;
			        	}
		             var selectFocusNode = window.getSelection().focusNode;
		             if(window.getSelection().focusNode.parentNode.tagName=="A"
		            	 ||window.getSelection().focusNode.parentNode.tagName=="SPAN"){
		                selectFocusNode = window.getSelection().focusNode.parentNode;
		             }
		           //ie浏览器，把结束点为最后面的，会获取为外面父节点
				        if((window.getSelection().focusNode.tagName=="P"
				        		||window.getSelection().focusNode.tagName=="H1"
				        			||window.getSelection().focusNode.tagName=="H2"||window.getSelection().focusNode.tagName=="H3")&&window.getSelection().focusOffset==0){
				        	selectFocusNode=contentChild[0];
				        	star=0;
				        }
				      //ie浏览器，把结束点为最后面的，会获取为外面父节点
				        if((window.getSelection().focusNode.tagName=="P"
				        		||window.getSelection().focusNode.tagName=="H1"
				        			||window.getSelection().focusNode.tagName=="H2"||window.getSelection().focusNode.tagName=="H3")&&window.getSelection().focusOffset!=0){
				        	selectFocusNode=contentChild[contentChild.length-1];
				        	end=contentChild[contentChild.length-1].textContent.length;
				        }
		             var starNode=0;
		             var endNode=0;
		             
					 for(var i=0;i<contentChild.length;i++){
						 if(selectAnchorNode==contentChild[i]){
							 starNode = i;
						 }
						 if(selectFocusNode==contentChild[i]){
							 endNode = i;
						 }
		              }
					 
					 if(starNode>endNode){
						 var t=endNode;
						 endNode=starNode;
						 starNode=t; 
						 var s=end;
						 end=star;
						 star=s;
						 var f=selectAnchorNode;
						 selectAnchorNode=selectFocusNode;
						 selectFocusNode=f;
					 }
					 
					 if(starNode==endNode&&star>end){
						 var s=end;
						 end=star;
						 star=s;
					 }
					 
					 //当选中的是同一块,没有样式的
					 if((starNode==endNode&&selectAnchorNode.tagName!="A")
							 &&(starNode==endNode&&selectAnchorNode.tagName!="SPAN")){
						 
						 var stringToStartText="";
						 for(var i=0;i<starNode;i++){
							 if(contentChild[i].tagName=="SPAN"&&contentChild[i].textContent==""){
							 		
							 }else if(contentChild[i].tagName=="BR"){
								 stringToStartText=stringToStartText+contentChild[i].outerHTML;
							 }else{
								 if(contentChild[i].length){
									 stringToStartText=stringToStartText+contentChild[i].textContent;
								 }else{
									 stringToStartText=stringToStartText+contentChild[i].outerHTML;
								 }
							 }
						 }
						 var stringToEndText="";
						 if(endNode!=(contentChild.length-1)){
							 for(var i=(endNode+1);i<contentChild.length;i++){
								 if(contentChild[i].tagName=="SPAN"&&contentChild[i].textContent==""){
								 		
								 }else if(contentChild[i].tagName=="BR"){
									 stringToEndText=stringToEndText+contentChild[i].outerHTML;
								 }else{
									 if(contentChild[i].length){
									 	stringToEndText=stringToEndText+contentChild[i].textContent;
									 }else{
									 	stringToEndText=stringToEndText+contentChild[i].outerHTML;
									 }
								 }

							 }
						 } 
						 var startText=window.getSelection().anchorNode.textContent.substring(0,star);
						 var endText=window.getSelection().focusNode.textContent.substring(end);
						 var centerText="<span style='background-color:"+chooseColor+";'>"+text+"</span>";
						 $scope.allElements[$scope.checkedItemId].content = stringToStartText+startText + centerText+endText+stringToEndText;
						 
						 return ;
					 }
					 
					 
					 
					 
					 var stringToStart="";
					 for(var i=0;i<starNode;i++){
						 if(contentChild[i].tagName=="SPAN"&&contentChild[i].textContent==""){
						 		
						 }else if(contentChild[i].tagName=="BR"){
							 stringToStart=stringToStart+contentChild[i].outerHTML;
						 }else{
							 if(contentChild[i].length){
								 
							 	stringToStart=stringToStart+contentChild[i].textContent;
					 		}else{
					 			stringToStart=stringToStart+contentChild[i].outerHTML;
					 		}
						 }
					 		
						 
					 }
					 var stringToEnd="";
					 if(endNode!=(contentChild.length-1)){
						 for(var i=(endNode+1);i<contentChild.length;i++){
							 if(contentChild[i].tagName=="SPAN"&&contentChild[i].textContent==""){
							 		
							 }else if(contentChild[i].tagName=="BR"){
								 stringToEnd=stringToEnd+contentChild[i].outerHTML;
							 }else{
								 if(contentChild[i].length){
								 	stringToEnd=stringToEnd+contentChild[i].textContent;
								 }else{
								 	stringToEnd=stringToEnd+contentChild[i].outerHTML;
								 }
							 }
						 }
					 }
					 var startA="";
					 if(selectAnchorNode.tagName=="A"){
						 if(star!=0){
							 if(selectAnchorNode.className.indexOf("inCode")>0){
								 var styleStr=$scope.styleStr(selectAnchorNode);
								 if(styleStr!=""){
									 startA="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
								 }else{
									 startA="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
								 }
								 
							 }else if(selectAnchorNode.className.indexOf("outCode")>0){
								 var styleStr=$scope.styleStr(selectAnchorNode);
								 if(styleStr!=""){
									 startA="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
								 }else{
									 startA="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
								 }
								 
							 }else{
								 var styleStr=$scope.styleStr(selectAnchorNode);
								 if(styleStr!=""){
									 startA="<a href='"+selectAnchorNode.href+"' style='"+styleStr+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
								 }else{
									 startA="<a href='"+selectAnchorNode.href+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
								 }
								 
							 }
							 
							 
						 }
					 }else if(selectAnchorNode.tagName=="SPAN"){
						 if(star!=0){
							 var styleStr=$scope.styleStr(selectAnchorNode);
							 if(styleStr!=""){
								 startA="<span style='"+styleStr+"'>"+selectAnchorNode.textContent.substring(0,star)+"</span>";
							 }else{
								 startA="<span>"+selectAnchorNode.textContent.substring(0,star)+"</span>";
							 }
							 
						 }
					 }else{
						 startA=selectAnchorNode.textContent.substring(0,star);
					 }
					 var endA="";
					 if(selectFocusNode.tagName=="A"){
						 if(end!=selectFocusNode.textContent.length){
							 if(selectFocusNode.className.indexOf("inCode")>0){
								 var styleStr=$scope.styleStr(selectFocusNode);
								 if(styleStr!=""){
									 endA="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"' style='"+styleStr+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
								 }else{
									 endA="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
								 }
								 
							 }else if(selectFocusNode.className.indexOf("outCode")>0){
								 var styleStr=$scope.styleStr(selectFocusNode);
								 if(styleStr!=""){
									 endA="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"' style='"+styleStr+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
								 }else{
									 endA="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
								 }
								 
							 }else{
								 var styleStr=$scope.styleStr(selectFocusNode);
								 if(styleStr!=""){
									 endA="<a href='"+selectFocusNode.href+"' style='"+styleStr+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
								 }else{
									 endA="<a href='"+selectFocusNode.href+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
								 }
								 
							 }
							 
						 }
					 }else if(selectFocusNode.tagName=="SPAN"){
						 if(end!=selectFocusNode.textContent.length){
							 var styleStr=$scope.styleStr(selectFocusNode);
							 if(styleStr!=""){
								 endA="<span style='"+styleStr+"'>"+selectFocusNode.textContent.substring(end)+"</span>";
							 }else{
								 endA="<span>"+selectFocusNode.textContent.substring(end)+"</span>";
							 }
							 
						 }
					 }else{
						 endA=selectFocusNode.textContent.substring(end);
					 }
					 
					 if(starNode==endNode){
						 if(selectAnchorNode.tagName=="A"){
							 if(isChangeFlag){
								 var styleStr=$scope.styleChange(selectAnchorNode,"backgroundColor");
								 
								 text="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"background-color:"+chooseColor+";'>"+text+"</a>";
							 }else{
								 var styleStr=$scope.styleChange(selectAnchorNode,"backgroundColor");
								 text="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"background-color:"+chooseColor+";'>"+text+"</a>";
							 }
							 $scope.allElements[$scope.checkedItemId].content = stringToStart + startA+text+endA + stringToEnd ;
							 
						 }else if(selectAnchorNode.tagName=="SPAN"){
							 if(isChangeFlag){
								 var styleStr=$scope.styleChange(selectAnchorNode,"backgroundColor");
								 text="<span style='"+styleStr+"background-color:"+chooseColor+";'>"+text+"</span>";
							 }else{
								 var styleStr=$scope.styleChange(selectAnchorNode,"backgroundColor");
								 text="<span style='"+styleStr+"background-color:"+chooseColor+";'>"+text+"</span>";
							 }
							 $scope.allElements[$scope.checkedItemId].content = stringToStart + startA+text+endA + stringToEnd ;
							 
						 }else{
							 text="<span style='background-color:"+chooseColor+";'>"+text+"</span>";
							 $scope.allElements[$scope.checkedItemId].content = stringToStart + startA+text+endA + stringToEnd ;
							
						 }
						 
					 }else{
						 var startText="";
						 if(selectAnchorNode.tagName=="A"){
							 if(isChangeFlag){
								 var styleStr=$scope.styleChange(selectAnchorNode,"backgroundColor");
								 startText="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"background-color:"+chooseColor+";'>"+selectAnchorNode.textContent.substring(star)+"</a>";
							 }else{
								 var styleStr=$scope.styleChange(selectAnchorNode,"backgroundColor");
								 startText="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"background-color:"+chooseColor+";'>"+selectAnchorNode.textContent.substring(star)+"</a>";
							 }
						 }else if(selectAnchorNode.tagName=="SPAN"){
							 if(isChangeFlag){
								 var styleStr=$scope.styleChange(selectAnchorNode,"backgroundColor");
								 startText="<span style='"+styleStr+"background-color:"+chooseColor+";'>"+selectAnchorNode.textContent.substring(star)+"</span>";
							 }else{
								 var styleStr=$scope.styleChange(selectAnchorNode,"backgroundColor");
								 startText="<span style='"+styleStr+"background-color:"+chooseColor+";'>"+selectAnchorNode.textContent.substring(star)+"</span>";
							 }
						 }else{
							 if(isChangeFlag){
								 startText=selectAnchorNode.textContent.substring(star); 
							 }else{
								 startText="<span style='background-color:"+chooseColor+";'>"+selectAnchorNode.textContent.substring(star)+"</span>";
							 }
							 
						 }
						 
						 var endText="";
						 if(selectFocusNode.tagName=="A"){
							 if(isChangeFlag){
								 var styleStr=$scope.styleChange(selectFocusNode,"backgroundColor");
								 endText="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"' style='"+styleStr+"background-color:"+chooseColor+";'>"+selectFocusNode.textContent.substring(0,end)+"</a>";
							 }else{
								 var styleStr=$scope.styleChange(selectFocusNode,"backgroundColor");
								 endText="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"' style='"+styleStr+"background-color:"+chooseColor+";'>"+selectFocusNode.textContent.substring(0,end)+"</a>";
							 } 
							
						 }else if(selectFocusNode.tagName=="SPAN"){
							 if(isChangeFlag){
								 var styleStr=$scope.styleChange(selectFocusNode,"backgroundColor");
								 endText="<span style='"+styleStr+"background-color:"+chooseColor+";'>"+selectFocusNode.textContent.substring(0,end)+"</span>";
							 }else{
								 var styleStr=$scope.styleChange(selectFocusNode,"backgroundColor");
								 endText="<span style='"+styleStr+"background-color:"+chooseColor+";'>"+selectFocusNode.textContent.substring(0,end)+"</span>";
							 } 
						 }else{
							 if(isChangeFlag){
								 endText=selectFocusNode.textContent.substring(0,end);
							 }else{
								 endText="<span style='background-color:"+chooseColor+";'>"+selectFocusNode.textContent.substring(0,end)+"</span>";
							 }
							 
						 }
						 var centerText="";
							 for(var i=starNode+1;i<endNode;i++){
								 if(contentChild[i].tagName=="SPAN"&&contentChild[i].textContent==""){
								 		
								 }else if(contentChild[i].tagName=="BR"){
									 centerText=centerText+contentChild[i].outerHTML;
								 }else{
									 if(contentChild[i].length){
										 if(isChangeFlag){
										
											 centerText=centerText+contentChild[i].textContent;
										 }else{
										
											 centerText=centerText+"<span style='background-color:"+chooseColor+";'>"+contentChild[i].textContent+"</span>";
										 }
									 
									 }else{
										 if(isChangeFlag){
											 contentChild[i].style.backgroundColor=chooseColor;
										 }else{
											 contentChild[i].style.backgroundColor=chooseColor;
										 }
										 centerText=centerText+contentChild[i].outerHTML;
									 }
								 }
							 }
							 $scope.allElements[$scope.checkedItemId].content = stringToStart + startA+startText+centerText+endText+endA + stringToEnd ;
						
					 }
					 
					 
					
				 } 
				 window.getSelection().removeAllRanges();
				
		   };
		   
		   
		   var currentFontColor="#000000";
		   var currentFontBgColor="#000000";
		   $scope.clickItem=function(event,elementId){
			   $scope.checkedItemId=elementId;
			   $scope.clearCheck();
			   getElementArr($scope);
			   $scope.allElements[elementId].checked=true;
			   $scope.setParamFlag=false;
			   closePanel();
			   if($scope.allElements[elementId].type=="content"||$scope.allElements[elementId].type=="title"){
				   $("#fontColor").colorpicker({
		                fillcolor:true,
		                reset:function(obj){
		                	
		                	$scope.fontColorChange("",false);
		                	
		                	$(obj).val("");
		                },
		                success:function(obj,color){
		                	if(currentFontColor==color){
		                		$scope.fontColorChange(color,true);
		                	}else{
		                		$scope.fontColorChange(color,false);
		                	}
		                	
		                   $(obj).val(color);	
		 				   $(obj).css("color",color);
		                }
		            });
				   $("#fontBgColor").colorpicker({
		                fillcolor:true,
		                reset:function(obj){
		                	$scope.fontBgColorChange("",false);
		                	$(obj).val("");
		                },
		                success:function(obj,color){
		                	if(currentFontBgColor==color){
		                		$scope.fontBgColorChange(color,true);
		                	}else{
		                		$scope.fontBgColorChange(color,false);
		                	}
		                		
		                	
		                	//$scope.allElements[elementId].bgImage=color;
		                   $(obj).val(color);	
		 				   $(obj).css("color",color);
		                }
		            });
				   var text=window.getSelection?window.getSelection().toString():(document.getSelection?document.getSelection():(document.selection?document.selection.createRange().text:""));
				   		if(window.getSelection().anchorNode){
				   			var contentChild=window.getSelection().anchorNode.parentNode.childNodes;
				        	if(window.getSelection().anchorNode.parentNode.tagName=="A"||window.getSelection().anchorNode.parentNode.tagName=="SPAN"){
				        		contentChild=window.getSelection().anchorNode.parentNode.parentNode.childNodes;
				        	}
				        	//ie浏览器，把起始点为最前面的，会获取为外面父节点
				        	if(window.getSelection().anchorNode.tagName=="P"
				        		||window.getSelection().anchorNode.tagName=="H1"
				        			||window.getSelection().anchorNode.tagName=="H2"||window.getSelection().anchorNode.tagName=="H3"){
				        		contentChild=window.getSelection().anchorNode.childNodes;
				        	}
				        	var starNode = 0;
				               var endNode = 0;
				               var selectAnchorNode = window.getSelection().anchorNode;
				               if(window.getSelection().anchorNode.parentNode.tagName=="A" ||window.getSelection().anchorNode.parentNode.tagName=="SPAN"){
				               	selectAnchorNode = window.getSelection().anchorNode.parentNode;
				               }
				             //ie浏览器，把起始点为最前面的，会获取为外面父节点
					        	if((window.getSelection().anchorNode.tagName=="P"
					        		||window.getSelection().anchorNode.tagName=="H1"
					        			||window.getSelection().anchorNode.tagName=="H2"||window.getSelection().anchorNode.tagName=="H3")&&window.getSelection().anchorOffset==0){
					        		selectAnchorNode=contentChild[0];
					        	}
					        	//ie浏览器，把起始点为最前面的，会获取为外面父节点
					        	if((window.getSelection().anchorNode.tagName=="P"
					        		||window.getSelection().anchorNode.tagName=="H1"
					        			||window.getSelection().anchorNode.tagName=="H2"||window.getSelection().anchorNode.tagName=="H3")&&window.getSelection().anchorOffset!=0){
					        		selectAnchorNode=contentChild[contentChild.length-1];
					        	}
				               var selectFocusNode = window.getSelection().focusNode;
				               if(window.getSelection().focusNode.parentNode.tagName=="A"||window.getSelection().focusNode.parentNode.tagName=="SPAN"){
				               	selectFocusNode = window.getSelection().focusNode.parentNode;
				               }
				             //ie浏览器，把结束点为最后面的，会获取为外面父节点
						        if((window.getSelection().focusNode.tagName=="P"
						        		||window.getSelection().focusNode.tagName=="H1"
						        			||window.getSelection().focusNode.tagName=="H2"||window.getSelection().focusNode.tagName=="H3")&&window.getSelection().focusOffset==0){
						        	selectFocusNode=contentChild[0];
						        }
						      //ie浏览器，把结束点为最后面的，会获取为外面父节点
						        if((window.getSelection().focusNode.tagName=="P"
						        		||window.getSelection().focusNode.tagName=="H1"
						        			||window.getSelection().focusNode.tagName=="H2"||window.getSelection().focusNode.tagName=="H3")&&window.getSelection().focusOffset!=0){
						        	selectFocusNode=contentChild[contentChild.length-1];
						        }
							 	for(var i=0;i<contentChild.length;i++){
				                   if(selectAnchorNode==contentChild[i]){
				                       starNode = i;
				                   }
				                   if(selectFocusNode==contentChild[i]){
				                       endNode = i;
				                   }
				               }
							
							 if(text!=""){
								 var fontColor="";
								 var fontBgColor="";
								 var fontColorFlag=false;
								 var fontBgColorFlag=false;
								 for(var i=starNode;i<endNode+1;i++){
									 if(contentChild[i].tagName=="A"||contentChild[i].tagName=="SPAN"){
										 if(i==starNode){
											 fontColor=contentChild[i].style.color;
											 fontBgColor=contentChild[i].style.backgroundColor;
										 }
										 if(fontColor!=contentChild[i].style.color){
											 fontColorFlag=true;
										 }
										 if(fontBgColor!=contentChild[i].style.backgroundColor){
											 fontBgColorFlag=true;
										 }
									 }else{
										 if(i==starNode){
											 fontColor="#000000";
											 fontBgColor="#000000";
										 }
										 if(fontColor!="#000000"){
											 fontColorFlag=true;
										 }
										 if(fontBgColor!="#000000"){
											 fontBgColorFlag=true;
										 }
									 }
								 }
								 if(fontColorFlag){
									 $("#fontColor").val("");	
					 				  
								 }else{
									 $("#fontColor").val(fontColor);	
									 $("#fontColor").css("color",fontColor);
								 }
								 if(fontBgColorFlag){
									 $("#fontBgColor").val("");	
					 				  
								 }else{
									 $("#fontBgColor").val(fontBgColor);	
									 $("#fontBgColor").css("color",fontBgColor);
								 }
							 }else{
								 if(selectAnchorNode.tagName=="A"||selectAnchorNode.tagName=="SPAN"){
									 $("#fontColor").val(selectAnchorNode.style.color);	
									 $("#fontColor").css("color",selectAnchorNode.style.color);
									 $("#fontBgColor").val(selectAnchorNode.style.backgroundColor);	
									 $("#fontBgColor").css("color",selectAnchorNode.style.backgroundColor);
								 }else{
									 $("#fontColor").val("#000000");	
									 $("#fontColor").css("color","#000000");
									 $("#fontBgColor").val("#000000");	
									 $("#fontBgColor").css("color","#000000");
								 }
								 
							 }
				   		}
			    	   
						 
			       		
				   /*$('#bgImg').val($scope.allElements[elementId].bgImage);	
				   $('#bgImg').css("color",$scope.allElements[elementId].bgImage);*/
			   }
			   if($scope.allElements[elementId].type=="title"||$scope.allElements[elementId].type=="content"){
				   var text=window.getSelection?window.getSelection().toString():(document.getSelection?document.getSelection():(document.selection?document.selection.createRange().text:""));
				   if(text!=""){
			             if(window.getSelection().anchorNode.parentNode.tagName=="A"
			            	 ||window.getSelection().anchorNode.parentNode.tagName=="SPAN"){
			                var selectAnchorNode = window.getSelection().anchorNode.parentNode;
			                if(selectAnchorNode.style.fontWeight=="bold"){
			                	$scope.currentFontWeight=true;
			                }else{
			                	$scope.currentFontWeight=false;
			                }
			                if(selectAnchorNode.style.fontStyle=="italic"){
			                	$scope.currentFontStyle=true;
			                }else{
			                	$scope.currentFontStyle=false;
			                }
			                if(selectAnchorNode.style.textDecoration=="underline"){
			                	$scope.currentTextDecoration=true;
			                }else{
			                	$scope.currentTextDecoration=false;
			                }
			             }
			             
			             if(window.getSelection().focusNode.parentNode.tagName=="A"
			            	 ||window.getSelection().focusNode.parentNode.tagName=="SPAN"){
			               var selectFocusNode = window.getSelection().focusNode.parentNode;
			               if(selectFocusNode.style.fontWeight=="bold"){
			                	$scope.currentFontWeight=true;
			                }else{
			                	$scope.currentFontWeight=false;
			                }
			               if(selectFocusNode.style.fontStyle=="italic"){
			            	   $scope.currentFontStyle=true;
			               }else{
			            	   $scope.currentFontStyle=false;
			               }
			               if(selectFocusNode.style.textDecoration=="underline"){
			                	$scope.currentTextDecoration=true;
			                }else{
			                	$scope.currentTextDecoration=false;
			                }
			             }
			             if(window.getSelection().focusNode.parentNode.tagName!="A"
			            	 &&window.getSelection().focusNode.parentNode.tagName!="SPAN"
			            	 &&window.getSelection().anchorNode.parentNode.tagName!="A"
			            		 &&window.getSelection().anchorNode.parentNode.tagName!="SPAN"){
			            	 $scope.currentFontWeight=false;
			            	 $scope.currentFontStyle=false;
			            	 $scope.currentTextDecoration=false;
			             }
				   }else{
					   $scope.currentFontWeight=false;
					   $scope.currentFontStyle=false;
					   $scope.currentTextDecoration=false;
				   }
			   }
			   event.stopPropagation();
		   };
		  
		   
		   
		   $scope.clickAudioItem=function(event,elementId){
			   $scope.checkedItemId=elementId;
			   $scope.clearCheck();
			   getElementArr($scope);
			   $scope.allElements[elementId].checked=true;
			   $scope.setParamFlag=false;
			   closePanel();
			   /*var audio=document.getElementById("hidden_"+elementId);
			   if(audio.paused){
				   audio.play();
			   }else{
				   audio.pause();
			   } */
			   event.stopPropagation();
		   };
		    
		   $scope.onPageClick=function(){
			   var text=window.getSelection?window.getSelection().toString():(document.getSelection?document.getSelection():(document.selection?document.selection.createRange().text:""));
		       if(text==''){
		    	   $scope.checkedItemId=null;
				   $scope.clearCheck();
				   $scope.addTitleFlag=false;
				   $scope.addFontStyle=false;
				   $scope.addDocFlag=false;
				   $scope.setParamFlag=false;
				   $scope.addMediaFlag=false;
		       }
		       closePanel();
			   
		   };
		   
		   $scope.addFontStyleEvent=function(){
			   
			   $scope.addFontStyle=true;
		   };
		   
		   $scope.audioPlay=function(){
			   audio = document.createElement("audio");
			   audio.src=$scope.allElements[item].src;
			   audio.play();
		   };
		   
		   $scope.clearCheck=function(){
			   for(var item in $scope.allElements){
				   $scope.allElements[item].checked=false;
				}
		   };
		   
		   $scope.changeLock=function(flag,viewFlag){
			   if(viewFlag){
				   $scope.allElements[$scope.checkedItemId].imageWidthLock=flag;
			   }else{
				   $scope.currentPic.imageWidthLock=flag;
				   
			   }
			   
		   };
		   
		   $scope.imageSizeChange=function(isNormalSize,flag){
			 if(flag){
				 if(isNormalSize){
					 $scope.allElements[$scope.checkedItemId].width="100%";
					 $scope.allElements[$scope.checkedItemId].height="auto";
				 }else{
					 $scope.allElements[$scope.checkedItemId].width="100";
					 $scope.allElements[$scope.checkedItemId].height="100";
					 //$scope.changeWidthEvent(100,flag);
				 }
				 
			 }else{
				 if(isNormalSize){
					 $scope.currentPic.width="100%";
					 $scope.currentPic.height="auto";
				 }else{
					 $scope.currentPic.width="100";
					 $scope.currentPic.height="100";
					 //$scope.changeWidthEvent(100,flag);
				 }
			 }  
		   };
		   
		   $scope.changeWidthEvent=function(width,flag){
			   if(flag){
				   if($scope.allElements[$scope.checkedItemId].src==""){
					   alert("请先上传文件");
					   
				   }
				   if($scope.allElements[$scope.checkedItemId].imageWidthLock){
					   var normalWidth=0;
					   var normalHeight=0;
					   var img_url = $scope.allElements[$scope.checkedItemId].src;
					   
					   // 创建对象
					   var img = new Image();
					 
					   // 改变图片的src
					   img.src = img_url;
					 
					   // 判断是否有缓存
					   if(img.complete){
						   // 打印
						   normalWidth=img.width;
						   normalHeight=img.height;
						  // alert('from:complete : width:'+img.width+',height:'+img.height);
					   }else{
						   // 加载完成执行
						   img.onload = function(){
							   // 打印
							   normalWidth=img.width;
							   normalHeight=img.height;
							   //alert('from:onload : width:'+img.width+',height:'+img.height);
						   };
					   }
					   if(normalHeight>0){
						   $scope.allElements[$scope.checkedItemId].height=parseInt((new Number(width)/new Number(normalWidth))*new Number(normalHeight));
					   }
	 
				   }
			   }else{
				   if($scope.currentPic.url==""){
					   alert("请先上传文件");
				   }
				   if($scope.currentPic.imageWidthLock){
					   var normalWidth=0;
					   var normalHeight=0;
					   var img_url = $scope.currentPic.url;
					   
					   // 创建对象
					   var img = new Image();
					 
					   // 改变图片的src
					   img.src = img_url;
					 
					   // 判断是否有缓存
					   if(img.complete){
						   // 打印
						   normalWidth=img.width;
						   normalHeight=img.height;
						  // alert('from:complete : width:'+img.width+',height:'+img.height);
					   }else{
						   // 加载完成执行
						   img.onload = function(){
							   // 打印
							   normalWidth=img.width;
							   normalHeight=img.height;
							   //alert('from:onload : width:'+img.width+',height:'+img.height);
						   };
					   }
					   if(normalHeight>0){
						   $scope.currentPic.height=parseInt((new Number(width)/new Number(normalWidth))*new Number(normalHeight));
					   }
	 
				   }
			   }
			   
		   };
		   
		   $scope.changeHeightEvent=function(height,flag){
			   if(flag){
				   if($scope.allElements[$scope.checkedItemId].src==""){
					   alert("请先上传文件");
				   }
				   if($scope.allElements[$scope.checkedItemId].imageWidthLock){
					   var normalWidth=0;
					   var normalHeight=0;
					   var img_url = $scope.allElements[$scope.checkedItemId].src;
					   
					   // 创建对象
					   var img = new Image();
					 
					   // 改变图片的src
					   img.src = img_url;
					 
					   // 判断是否有缓存
					   if(img.complete){
						   // 打印
						   normalWidth=img.width;
						   normalHeight=img.height;
						  // alert('from:complete : width:'+img.width+',height:'+img.height);
					   }else{
						   // 加载完成执行
						   img.onload = function(){
							   // 打印
							   normalWidth=img.width;
							   normalHeight=img.height;
							   //alert('from:onload : width:'+img.width+',height:'+img.height);
						   };
					   }
					   if(normalWidth>0){
						   $scope.allElements[$scope.checkedItemId].width=parseInt((new Number(height)/new Number(normalHeight))*new Number(normalWidth));
					   }
	 
				   }
			   }else{
				   if($scope.currentPic.url==""){
					   alert("请先上传文件");
				   }
				   if($scope.currentPic.imageWidthLock){
					   var normalWidth=0;
					   var normalHeight=0;
					   var img_url = $scope.currentPic.url;
					   
					   // 创建对象
					   var img = new Image();
					 
					   // 改变图片的src
					   img.src = img_url;
					 
					   // 判断是否有缓存
					   if(img.complete){
						   // 打印
						   normalWidth=img.width;
						   normalHeight=img.height;
						  // alert('from:complete : width:'+img.width+',height:'+img.height);
					   }else{
						   // 加载完成执行
						   img.onload = function(){
							   // 打印
							   normalWidth=img.width;
							   normalHeight=img.height;
							   //alert('from:onload : width:'+img.width+',height:'+img.height);
						   };
					   }
					   if(normalWidth>0){
						   $scope.currentPic.width=parseInt((new Number(height)/new Number(normalHeight))*new Number(normalWidth));
					   }
	 
				   }
			   }
			   
		   };
		   
		   //点击添加超链接，加载当前元素的链接，弹出窗口
		   var range=null;
		   $scope.urlIsEditor=false;
		   $scope.urlFlag=false;//表示超链接，不用去再转换了
		   $scope.addUrl=function(){
			   range=null;
			   $scope.urlIsEditor=false;
			   var text=window.getSelection?window.getSelection().toString():(document.getSelection?document.getSelection():(document.selection?document.selection.createRange().text:""));
		       if(text!=''){
		    	   var contentChild=window.getSelection().anchorNode.parentNode.childNodes;
		        	if(window.getSelection().anchorNode.parentNode.tagName=="A"||window.getSelection().anchorNode.parentNode.tagName=="SPAN"){
		        		$scope.urlIsEditor=true;
		        		contentChild=window.getSelection().anchorNode.parentNode.parentNode.childNodes;
		        		//return ;
		        	}
		        	//ie浏览器，把起始点为最前面的，会获取为外面父节点
		        	if(window.getSelection().anchorNode.tagName=="P"
		        		||window.getSelection().anchorNode.tagName=="H1"
		        			||window.getSelection().anchorNode.tagName=="H2"||window.getSelection().anchorNode.tagName=="H3"){
		        		contentChild=window.getSelection().anchorNode.childNodes;
		        	}
		        	if(window.getSelection().focusNode.parentNode.tagName=="A"&&window.getSelection().focusNode.length!=window.getSelection().focusOffset){
		        		$scope.urlIsEditor=true;
		        		//return ;
		        	}
		        	
		        	if(window.getSelection) {
						   range=window.getSelection().getRangeAt(0);
					   } else if(document.selection && document.selection.createRange) {
						   range=document.selection.createRange();
					   }
		        	var starNode = 0;
		               var endNode = 0;
		               var selectAnchorNode = window.getSelection().anchorNode;
		               if(window.getSelection().anchorNode.parentNode.tagName=="A" ||window.getSelection().anchorNode.parentNode.tagName=="SPAN"){
		               	selectAnchorNode = window.getSelection().anchorNode.parentNode;
		               }
		               //ie浏览器，把起始点为最前面的，会获取为外面父节点
			        	if((window.getSelection().anchorNode.tagName=="P"
			        		||window.getSelection().anchorNode.tagName=="H1"
			        			||window.getSelection().anchorNode.tagName=="H2"||window.getSelection().anchorNode.tagName=="H3")&&window.getSelection().anchorOffset==0){
			        		selectAnchorNode=contentChild[0];
			        	}
			        	//ie浏览器，把起始点为最前面的，会获取为外面父节点
			        	if((window.getSelection().anchorNode.tagName=="P"
			        		||window.getSelection().anchorNode.tagName=="H1"
			        			||window.getSelection().anchorNode.tagName=="H2"||window.getSelection().anchorNode.tagName=="H3")&&window.getSelection().anchorOffset!=0){
			        		selectAnchorNode=contentChild[contentChild.length-1];
			        	}
		               var selectFocusNode = window.getSelection().focusNode;
		               if(window.getSelection().focusNode.parentNode.tagName=="A"||window.getSelection().focusNode.parentNode.tagName=="SPAN"){
		               	selectFocusNode = window.getSelection().focusNode.parentNode;
		               }
		             //ie浏览器，把结束点为最后面的，会获取为外面父节点
				        if((window.getSelection().focusNode.tagName=="P"
				        		||window.getSelection().focusNode.tagName=="H1"
				        			||window.getSelection().focusNode.tagName=="H2"||window.getSelection().focusNode.tagName=="H3")&&window.getSelection().focusOffset==0){
				        	selectFocusNode=contentChild[0];
				        }
				      //ie浏览器，把结束点为最后面的，会获取为外面父节点
				        if((window.getSelection().focusNode.tagName=="P"
				        		||window.getSelection().focusNode.tagName=="H1"
				        			||window.getSelection().focusNode.tagName=="H2"||window.getSelection().focusNode.tagName=="H3")&&window.getSelection().focusOffset!=0){
				        	selectFocusNode=contentChild[contentChild.length-1];
				        }
					 	for(var i=0;i<contentChild.length;i++){
		                   if(selectAnchorNode==contentChild[i]){
		                       starNode = i;
		                   }
		                   if(selectFocusNode==contentChild[i]){
		                       endNode = i;
		                   }
		               }
					 
					 var hrefIndex=0;
					 var hrefSrc="";
					 for(var i=starNode;i<endNode+1;i++){
						 if(contentChild[i].tagName=="A"){
							 hrefIndex=hrefIndex+1;
							 hrefSrc=contentChild[i].href;
							 $scope.urlIsEditor=true;
							 $scope.currentUrl=hrefSrc;
							 if(contentChild[i].className.indexOf("inCode__")>0){
								 $scope.currentUrlType="In";
								 var className=contentChild[i].className;
								 $scope.currentUrlNodeId=className.substring(className.indexOf("inCode__")+8);
							 }else if(contentChild[i].className.indexOf("outCode__")>0){
								 $scope.currentUrlType="Out";
								 var className=contentChild[i].className;
								 $scope.currentUrlNodeId=className.substring(className.indexOf("outCode__")+9);
							 }
						 }
					 }
					 
					 if(hrefIndex!=1){ 
						 $scope.currentUrl="";
						 $scope.currentUrlType="No";
						 $scope.currentUrlNodeId="";
					 }
						 
					 loadUrlPage($scope,$http);
		       }else{
		    	   return ;
		       }
		   };
		   
		   
		   //超链接码内
		   $scope.inCodeHref=function(flag){
			   if(flag){
				   opts.inCode(function(value,nodeId) {
					   $scope.allElements[$scope.checkedItemId].hrefNodeId=nodeId;
					   $scope.allElements[$scope.checkedItemId].href=value;
					   $scope.$apply($scope.allElements[$scope.checkedItemId].hrefType="In");
					   $(".allHrefClassName").val(value);
					   
					   getElementArr($scope);
					});
			   }else{
				   opts.inCode(function(value,nodeId) {
					   $scope.currentUrlNodeId=nodeId;
					   $scope.currentUrl=value;
					   $scope.$apply($scope.currentUrlType="In");
					   $(".inOutCodeHref").val(value);
					});
				   $scope.currentUrlType="In";
			   }
			   
		   };
		   
		   
		   //超链接码外
		   $scope.outCodeHref=function(flag){
			   if(flag){
				   opts.outCode(function(value,nodeId) {
					   $scope.allElements[$scope.checkedItemId].hrefNodeId=nodeId;
					   $scope.allElements[$scope.checkedItemId].href=value;
					   $scope.$apply($scope.allElements[$scope.checkedItemId].hrefType="Out");
					   $(".allHrefClassName").val(value);
					   getElementArr($scope);
					});
			   }else{
				   opts.outCode(function(value,nodeId) {
					   $scope.currentUrlNodeId=nodeId;
					   $scope.currentUrl=value;
					   $scope.$apply($scope.currentUrlType="Out");
					   $(".inOutCodeHref").val(value);
					});
				   $scope.currentUrlType="Out";
			   }
			   
		   };
		   
		 
		   //超链接自定义
		   $scope.autoHref=function(){
			   $scope.currentUrlNodeId="";
			   $scope.currentUrl="";
			   $scope.currentUrlType="No";
		   };
		   
		   
		   $scope.inCode=function(index,flag){
			   if(flag){
				   opts.inCode(function(value,nodeId) {
					   $scope.allElements[$scope.checkedItemId].imagesSrc[index].hrefNodeId=nodeId;
					   $scope.allElements[$scope.checkedItemId].imagesSrc[index].href=value;
					   $scope.$apply($scope.allElements[$scope.checkedItemId].imagesSrc[index].hrefType="In");
					   $(".tpHrefClass"+index).val(value);
					  
					});
			   }else{
				   opts.inCode(function(value,nodeId) {
					   $scope.currentPic.imagesUrl[index].hrefNodeId=nodeId;
					   $scope.currentPic.imagesUrl[index].href=value;
					   $scope.$apply($scope.currentPic.imagesUrl[index].hrefType="In");
					   $(".hrefClass"+index).val(value);
					  
					});
			   }
			   
		   };
		   
		   $scope.outCode=function(index,flag){
			   if(flag){
				   opts.outCode(function(value,nodeId) {
					   $scope.allElements[$scope.checkedItemId].imagesSrc[index].hrefNodeId=nodeId;
					   $scope.allElements[$scope.checkedItemId].imagesSrc[index].href=value;
					   $scope.$apply($scope.allElements[$scope.checkedItemId].imagesSrc[index].hrefType="Out");
					   $(".tpHrefClass"+index).val(value);
					});
			   }else{
				   opts.outCode(function(value,nodeId) {
					   $scope.currentPic.imagesUrl[index].hrefNodeId=nodeId;
					   $scope.currentPic.imagesUrl[index].href=value;
					   $scope.$apply($scope.currentPic.imagesUrl[index].hrefType="Out");
					   $(".hrefClass"+index).val(value);
					});
			   }
			   
		   };
		   
		   //保存超链接
		   $scope.saveUrl=function(){
			   window.getSelection().removeAllRanges();
			   if(window.getSelection &&range!=null) {
				   window.getSelection().addRange(range);
			   } else if(document.selection && document.selection.createRange &&range!=null) {
				   document.selection.createRange(range);
			   }  
			   if($scope.currentUrlType=="No"){
				   $scope.currentUrl=$(".autoHref").val();
			   }
		       var url=$scope.currentUrl;
			   var text=window.getSelection?window.getSelection().toString():(document.getSelection?document.getSelection():(document.selection?document.selection.createRange().text:""));
				 if(text!=""){
					 var contentChild=new Array();
					 if(window.getSelection().anchorNode.parentNode.tagName=="A"
						 ||window.getSelection().anchorNode.parentNode.tagName=="SPAN"){
						 contentChild=window.getSelection().anchorNode.parentNode.parentNode.childNodes;
					 }else{
						 contentChild=window.getSelection().anchorNode.parentNode.childNodes;
					 }
					 
					 var star = window.getSelection().anchorOffset;
		             var end = window.getSelection().focusOffset;
					//ie浏览器，把起始点为最前面的，会获取为外面父节点
			        	if(window.getSelection().anchorNode.tagName=="P"
			        		||window.getSelection().anchorNode.tagName=="H1"
			        			||window.getSelection().anchorNode.tagName=="H2"||window.getSelection().anchorNode.tagName=="H3"){
			        		contentChild=window.getSelection().anchorNode.childNodes;
			        	}
					 var selectAnchorNode = window.getSelection().anchorNode;
		             if(window.getSelection().anchorNode.parentNode.tagName=="A"
		            	 ||window.getSelection().anchorNode.parentNode.tagName=="SPAN"){
		                selectAnchorNode = window.getSelection().anchorNode.parentNode;
		             }
		           //ie浏览器，把起始点为最前面的，会获取为外面父节点
			        	if((window.getSelection().anchorNode.tagName=="P"
			        		||window.getSelection().anchorNode.tagName=="H1"
			        			||window.getSelection().anchorNode.tagName=="H2"||window.getSelection().anchorNode.tagName=="H3")&&window.getSelection().anchorOffset==0){
			        		selectAnchorNode=contentChild[0];
			        		star=0;
			        	}
			        	//ie浏览器，把起始点为最前面的，会获取为外面父节点
			        	if((window.getSelection().anchorNode.tagName=="P"
			        		||window.getSelection().anchorNode.tagName=="H1"
			        			||window.getSelection().anchorNode.tagName=="H2"||window.getSelection().anchorNode.tagName=="H3")&&window.getSelection().anchorOffset!=0){
			        		selectAnchorNode=contentChild[contentChild.length-1];
			        		end=contentChild[contentChild.length-1].textContent.length;
			        	}
		             var selectFocusNode = window.getSelection().focusNode;
		             if(window.getSelection().focusNode.parentNode.tagName=="A"
		            	 ||window.getSelection().focusNode.parentNode.tagName=="SPAN"){
		                selectFocusNode = window.getSelection().focusNode.parentNode;
		             }
		           //ie浏览器，把结束点为最后面的，会获取为外面父节点
				        if((window.getSelection().focusNode.tagName=="P"
				        		||window.getSelection().focusNode.tagName=="H1"
				        			||window.getSelection().focusNode.tagName=="H2"||window.getSelection().focusNode.tagName=="H3")&&window.getSelection().focusOffset==0){
				        	selectFocusNode=contentChild[0];
				        	star=0;
				        }
				      //ie浏览器，把结束点为最后面的，会获取为外面父节点
				        if((window.getSelection().focusNode.tagName=="P"
				        		||window.getSelection().focusNode.tagName=="H1"
				        			||window.getSelection().focusNode.tagName=="H2"||window.getSelection().focusNode.tagName=="H3")&&window.getSelection().focusOffset!=0){
				        	selectFocusNode=contentChild[contentChild.length-1];
				        	end=contentChild[contentChild.length-1].textContent.length;
				        }
		             var starNode=0;
		             var endNode=0;
		             
					 for(var i=0;i<contentChild.length;i++){
						 if(selectAnchorNode==contentChild[i]){
							 starNode = i;
						 }
						 if(selectFocusNode==contentChild[i]){
							 endNode = i;
						 }
		              }
					 
					 if(starNode>endNode){
						 var t=endNode;
						 endNode=starNode;
						 starNode=t; 
						 var s=end;
						 end=star;
						 star=s;
						 var f=selectAnchorNode;
						 selectAnchorNode=selectFocusNode;
						 selectFocusNode=f;
					 }
					 
					 if(starNode==endNode&&star>end){
						 var s=end;
						 end=star;
						 star=s;
					 }
					 
					 
					
					 //当选中的是同一块,没有样式的
					 if((starNode==endNode&&selectAnchorNode.tagName!="A")
							 &&(starNode==endNode&&selectAnchorNode.tagName!="SPAN")){
						 
						 var stringToStartText="";
						 for(var i=0;i<starNode;i++){
							 if(contentChild[i].tagName=="SPAN"&&contentChild[i].textContent==""){
							 		
							 }else if(contentChild[i].tagName=="BR"){
								 stringToStartText=stringToStartText+contentChild[i].outerHTML;
							 }else{
								 if(contentChild[i].length){
									 stringToStartText=stringToStartText+contentChild[i].textContent;
								 }else{
									 stringToStartText=stringToStartText+contentChild[i].outerHTML;
								 }
							 }
						 }
						 var stringToEndText="";
						 if(endNode!=(contentChild.length-1)){
							 for(var i=(endNode+1);i<contentChild.length;i++){
								 if(contentChild[i].tagName=="SPAN"&&contentChild[i].textContent==""){
								 		
								 }else if(contentChild[i].tagName=="BR"){
									 stringToEndText=stringToEndText+contentChild[i].outerHTML;
								 }else{
									 if(contentChild[i].length){
										 stringToEndText=stringToEndText+contentChild[i].textContent;
									 }else{
										 stringToEndText=stringToEndText+contentChild[i].outerHTML;
									 }
								 }
							 }
						 } 
						 var startText=selectAnchorNode.textContent.substring(0,star);
						 var endText=selectFocusNode.textContent.substring(end);
						 var centerText="";
						 if($scope.currentUrlType=="In"){
							 centerText="<a href='"+url+"' class='__resource__inCode__"+$scope.currentUrlNodeId+"'>"+text+"</a>";
     			 		}else if($scope.currentUrlType=="Out"){
     			 			centerText="<a href='"+url+"' class='__resource__outCode__"+$scope.currentUrlNodeId+"'>"+text+"</a>";
     			 		}else{
     			 			centerText="<a href='"+url+"'>"+text+"</a>";
     			 		}
						 //var centerText="<span style='font-weight:bold;'>"+text+"</span>";
						 $scope.allElements[$scope.checkedItemId].content = stringToStartText+startText + centerText+endText+stringToEndText;
						 $scope.urlFlag=true;
						
						 $scope.currentUrl="";
						 $scope.currentUrlType="No";
						 $('#urlModal').modal('hide');
						 window.getSelection().removeAllRanges();
						 return ;
					 }
					 
					 
					 
					 var stringToStart="";
					 for(var i=0;i<starNode;i++){
						 if(contentChild[i].tagName=="SPAN"&&contentChild[i].textContent==""){
						 		
						 }else if(contentChild[i].tagName=="BR"){
							 stringToStart=stringToStart+contentChild[i].outerHTML;
						 }else{
							 if(contentChild[i].length){
							 
								 stringToStart=stringToStart+contentChild[i].textContent;
							 }else{
								 stringToStart=stringToStart+contentChild[i].outerHTML;
							 }
						 }
						 
					 }
					 var stringToEnd="";
					 if(endNode!=(contentChild.length-1)){
						 for(var i=(endNode+1);i<contentChild.length;i++){
							 if(contentChild[i].tagName=="SPAN"&&contentChild[i].textContent==""){
							 		
							 }else if(contentChild[i].tagName=="BR"){
								 stringToEnd=stringToEnd+contentChild[i].outerHTML;
							 }else{
								 if(contentChild[i].length){
									 stringToEnd=stringToEnd+contentChild[i].textContent;
								 }else{
									 stringToEnd=stringToEnd+contentChild[i].outerHTML;
								 }
							 }
						 }
					 }
					 var startA="";
					 if(selectAnchorNode.tagName=="A"){
						 if(star!=0){
							 if(selectAnchorNode.className.indexOf("inCode")>0){
								 var styleStr=$scope.styleStr(selectAnchorNode);
								 if(styleStr!=""){
									 startA="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
								 }else{
									 startA="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
								 }
								 
							 }else if(selectAnchorNode.className.indexOf("outCode")>0){
								 var styleStr=$scope.styleStr(selectAnchorNode);
								 if(styleStr!=""){
									 startA="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
								 }else{
									 startA="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
								 }
								 
							 }else{
								 var styleStr=$scope.styleStr(selectAnchorNode);
								 if(styleStr!=""){
									 startA="<a href='"+selectAnchorNode.href+"' style='"+styleStr+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
								 }else{
									 startA="<a href='"+selectAnchorNode.href+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
								 }
								 
							 }
							 
							 
						 }
					 }else if(selectAnchorNode.tagName=="SPAN"){
						 if(star!=0){
							 var styleStr=$scope.styleStr(selectAnchorNode);
							 if(styleStr!=""){
								 startA="<span style='"+styleStr+"'>"+selectAnchorNode.textContent.substring(0,star)+"</span>";
							 }else{
								 startA="<span>"+selectAnchorNode.textContent.substring(0,star)+"</span>";
							 }
							 
						 }
					 }else{
						 startA=selectAnchorNode.textContent.substring(0,star);
					 }
					 var endA="";
					 if(selectFocusNode.tagName=="A"){
						 if(end!=selectFocusNode.textContent.length){
							 if(selectFocusNode.className.indexOf("inCode")>0){
								 var styleStr=$scope.styleStr(selectFocusNode);
								 if(styleStr!=""){
									 endA="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"' style='"+styleStr+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
								 }else{
									 endA="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
								 }
								 
							 }else if(selectFocusNode.className.indexOf("outCode")>0){
								 var styleStr=$scope.styleStr(selectFocusNode);
								 if(styleStr!=""){
									 endA="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"' style='"+styleStr+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
								 }else{
									 endA="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
								 }
								 
							 }else{
								 var styleStr=$scope.styleStr(selectFocusNode);
								 if(styleStr!=""){
									 endA="<a href='"+selectFocusNode.href+"' style='"+styleStr+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
								 }else{
									 endA="<a href='"+selectFocusNode.href+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
								 }
								 
							 }
							 
						 }
					 }else if(selectFocusNode.tagName=="SPAN"){
						 if(end!=selectFocusNode.textContent.length){
							 var styleStr=$scope.styleStr(selectFocusNode);
							 if(styleStr!=""){
								 endA="<span style='"+styleStr+"'>"+selectFocusNode.textContent.substring(end)+"</span>";
							 }else{
								 endA="<span>"+selectFocusNode.textContent.substring(end)+"</span>";
							 }
							 
						 }
					 }else{
						 endA=selectFocusNode.textContent.substring(end);
					 }
					 
					 if(starNode==endNode){
						 if(selectAnchorNode.tagName=="A"||selectAnchorNode.tagName=="SPAN"){
		                	if($scope.currentUrlType=="In"){
		                		var styleStr=$scope.styleStr(contentChild[starNode]);
		        			 	if(styleStr!=""){
		        			 		text="<a href='"+url+"' class='__resource__inCode__"+$scope.currentUrlNodeId+"' style='"+styleStr+"'>"+text+"</a>";
		        			 	}else{
		        			 		text="<a href='"+url+"' class='__resource__inCode__"+$scope.currentUrlNodeId+"'>"+text+"</a>";
		        			 	}
		            					
		        			 }else if($scope.currentUrlType=="Out"){
		        			 	var styleStr=$scope.styleStr(contentChild[starNode]);
		        			 	if(styleStr!=""){
		        			 		text="<a href='"+url+"' class='__resource__outCode__"+$scope.currentUrlNodeId+"' style='"+styleStr+"'>"+text+"</a>";
		        			 	}else{
		        			 		text="<a href='"+url+"' class='__resource__outCode__"+$scope.currentUrlNodeId+"'>"+text+"</a>";
		        			 	}
		        			 			
		        			 }else{
		        			 	var styleStr=$scope.styleStr(contentChild[starNode]);
		        			 	if(styleStr!=""){
		        			 		text="<a href='"+url+"' style='"+styleStr+"'>"+text+"</a>";
		        			 	}else{
		        			 		text="<a href='"+url+"'>"+text+"</a>";
		        			 	}
		        			 			
		        			 }
							 $scope.allElements[$scope.checkedItemId].content = stringToStart + startA+text+endA + stringToEnd ;
							 $scope.urlFlag=true;
						 }else{
							if($scope.currentUrlType=="In"){
								text="<a href='"+url+"' class='__resource__inCode__"+$scope.currentUrlNodeId+"'>"+text+"</a>";
							}else if($scope.currentUrlType=="Out"){
								text="<a href='"+url+"' class='__resource__outCode__"+$scope.currentUrlNodeId+"'>"+text+"</a>";
							}else{
								text="<a href='"+url+"'>"+text+"</a>";
							}
							$scope.allElements[$scope.checkedItemId].content = stringToStart + startA+text+endA + stringToEnd ;
							$scope.urlFlag=true;
							
						 }
					 }else{
						 var textCenter="";
						//如果开始节点和结束节点不同，for循环里面的
	                	for(var i=starNode;i<endNode+1;i++){
	                		if(i==starNode){
	                			if(contentChild[i].textContent.substring(star)!=""){
	                				if(contentChild[i].tagName=="A"||contentChild[i].tagName=="SPAN"){
	                        			if($scope.currentUrlType=="In"){
	                        				var styleStr=$scope.styleStr(contentChild[i]);
	                        				if(styleStr!=""){
	                        					textCenter=textCenter+"<a href='"+url+"' class='__resource__inCode__"+$scope.currentUrlNodeId+"' style='"+styleStr+"'>"+contentChild[i].textContent.substring(star)+"</a>";
	                        				}else{
	                        					textCenter=textCenter+"<a href='"+url+"' class='__resource__inCode__"+$scope.currentUrlNodeId+"'>"+contentChild[i].textContent.substring(star)+"</a>";
	                        				}
	                    			 	}else if($scope.currentUrlType=="Out"){
	                    			 		var styleStr=$scope.styleStr(contentChild[i]);
	                    			 		if(styleStr!=""){
	                    			 			textCenter=textCenter+"<a href='"+url+"' class='__resource__outCode__"+$scope.currentUrlNodeId+"' style='"+styleStr+"'>"+contentChild[i].textContent.substring(star)+"</a>";
	                    			 		}else{
	                    			 			textCenter=textCenter+"<a href='"+url+"' class='__resource__outCode__"+$scope.currentUrlNodeId+"'>"+contentChild[i].textContent.substring(star)+"</a>";
	                    			 		}
	                    			 			
	                    			 	}else{
	                    			 		var styleStr=$scope.styleStr(contentChild[i]);
	                    			 		if(styleStr!=""){
	                    			 			textCenter=textCenter+"<a href='"+url+"' style='"+styleStr+"'>"+contentChild[i].textContent.substring(star)+"</a>";
	                    			 		}else{
	                    			 			textCenter=textCenter+"<a href='"+url+"'>"+contentChild[i].textContent.substring(star)+"</a>";
	                    			 		}
	                    			 			
	                    			 	}
	                        		}else{
	                        			if($scope.currentUrlType=="In"){
	                        				textCenter=textCenter+"<a href='"+url+"' class='__resource__inCode__"+$scope.currentUrlNodeId+"'>"+contentChild[i].textContent.substring(star)+"</a>";
	                    			 	}else if($scope.currentUrlType=="Out"){
	                    			 		textCenter=textCenter+"<a href='"+url+"' class='__resource__outCode__"+$scope.currentUrlNodeId+"'>"+contentChild[i].textContent.substring(star)+"</a>";
	                    			 	}else{
	                    			 		textCenter=textCenter+"<a href='"+url+"'>"+contentChild[i].textContent.substring(star)+"</a>";
	                    			 	}
	                        		}
	                			}
	                				
	                		}else if(i==endNode){
	                			if(contentChild[i].textContent.substring(0,end)!=""){
	                				if(contentChild[i].tagName=="A"||contentChild[i].tagName=="SPAN"){

	                        			if($scope.currentUrlType=="In"){
	                        				var styleStr=$scope.styleStr(contentChild[i]);
	                    			 		if(styleStr!=""){
	                    			 			textCenter=textCenter+"<a href='"+url+"' class='__resource__inCode__"+$scope.currentUrlNodeId+"' style='"+styleStr+"'>"+contentChild[i].textContent.substring(0,end)+"</a>";
	                    			 		}else{
	                    			 			textCenter=textCenter+"<a href='"+url+"' class='__resource__inCode__"+$scope.currentUrlNodeId+"'>"+contentChild[i].textContent.substring(0,end)+"</a>";
	                    			 		}
	                        					
	                    			 	}else if($scope.currentUrlType=="Out"){
	                    			 		var styleStr=$scope.styleStr(contentChild[i]);
	                    			 		if(styleStr!=""){
	                    			 			textCenter=textCenter+"<a href='"+url+"' class='__resource__outCode__"+$scope.currentUrlNodeId+"' style='"+styleStr+"'>"+contentChild[i].textContent.substring(0,end)+"</a>";
	                    			 		}else{
	                    			 			textCenter=textCenter+"<a href='"+url+"' class='__resource__outCode__"+$scope.currentUrlNodeId+"'>"+contentChild[i].textContent.substring(0,end)+"</a>";
	                    			 		}
	                    			 			
	                    			 	}else{
	                    			 		var styleStr=$scope.styleStr(contentChild[i]);
	                    			 		if(styleStr!=""){
	                    			 			textCenter=textCenter+"<a href='"+url+"' style='"+styleStr+"'>"+contentChild[i].textContent.substring(0,end)+"</a>";
	                    			 		}else{
	                    			 			textCenter=textCenter+"<a href='"+url+"'>"+contentChild[i].textContent.substring(0,end)+"</a>";
	                    			 		}
	                    			 			
	                    			 	}
	                        		}else{
	                        			if($scope.currentUrlType=="In"){
	                        				textCenter=textCenter+"<a href='"+url+"' class='__resource__inCode__"+$scope.currentUrlNodeId+"'>"+contentChild[i].textContent.substring(0,end)+"</a>";
	                    			 	}else if($scope.currentUrlType=="Out"){
	                    			 		textCenter=textCenter+"<a href='"+url+"' class='__resource__outCode__"+$scope.currentUrlNodeId+"'>"+contentChild[i].textContent.substring(0,end)+"</a>";
	                    			 	}else{
	                    			 		textCenter=textCenter+"<a href='"+url+"'>"+contentChild[i].textContent.substring(0,end)+"</a>";
	                    			 	}
	                        		}
	            				}
	                				
	                		}else{
	                				
	                			if((contentChild[i].tagName=="A"||contentChild[i].tagName=="SPAN")&&contentChild[i].textContent!=""){
	                				if($scope.currentUrlType=="In"){
	                        			var styleStr=$scope.styleStr(contentChild[i]);
	                    			 	if(styleStr!=""){
	                    			 		textCenter=textCenter+"<a href='"+url+"' class='__resource__inCode__"+$scope.currentUrlNodeId+"' style='"+styleStr+"'>"+contentChild[i].textContent+"</a>";
	                    			 	}else{
	                    			 		textCenter=textCenter+"<a href='"+url+"' class='__resource__inCode__"+$scope.currentUrlNodeId+"'>"+contentChild[i].textContent+"</a>";
	                    			 	}
	                        					
	                    			 }else if($scope.currentUrlType=="Out"){
	                    			 	var styleStr=$scope.styleStr(contentChild[i]);
	                    			 	if(styleStr!=""){
	                    			 		textCenter=textCenter+"<a href='"+url+"' class='__resource__outCode__"+$scope.currentUrlNodeId+"' style='"+styleStr+"'>"+contentChild[i].textContent+"</a>";
	                    			 	}else{
	                    			 		textCenter=textCenter+"<a href='"+url+"' class='__resource__outCode__"+$scope.currentUrlNodeId+"'>"+contentChild[i].textContent+"</a>";
	                    			 	}
	                    			 			
	                    			 }else{
	                    			 	var styleStr=$scope.styleStr(contentChild[i]);
	                    			 	if(styleStr!=""){
	                    			 		textCenter=textCenter+"<a href='"+url+"' style='"+styleStr+"'>"+contentChild[i].textContent+"</a>";
	                    			 	}else{
	                    			 		textCenter=textCenter+"<a href='"+url+"'>"+contentChild[i].textContent+"</a>";
	                    			 	}
	                    			 			
	                    			 }
	                        	}else if(contentChild[i].tagName=="BR"){
	                        		textCenter=textCenter+contentChild[i].outerHTML;
	                        	}else{
	                        		if($scope.currentUrlType=="In"){
	                        			textCenter=textCenter+"<a href='"+url+"' class='__resource__inCode__"+$scope.currentUrlNodeId+"'>"+contentChild[i].textContent+"</a>";
	                    			 }else if($scope.currentUrlType=="Out"){
	                    			 	textCenter=textCenter+"<a href='"+url+"' class='__resource__outCode__"+$scope.currentUrlNodeId+"'>"+contentChild[i].textContent+"</a>";
	                    			 }else{
	                    			 	textCenter=textCenter+"<a href='"+url+"'>"+contentChild[i].textContent+"</a>";
	                    			 }
	                        	}
	                				
	                				
	                		}
	                			////如果开始节点和结束节点不同，for循环里面的////结束
	                    }	 
						$scope.allElements[$scope.checkedItemId].content = stringToStart + startA+textCenter+endA + stringToEnd ;
						$scope.urlFlag=true;
					 }
					 
				 } 
				 
				 $scope.urlFlag=true;
			 	$scope.currentUrl="";
			 	$scope.currentUrlType="No";
			 	$('#urlModal').modal('hide');
			 	window.getSelection().removeAllRanges();
				
		   };
		   
 
				 
				 $scope.styleStr=function(content){
					var styleStr="";
 					if(content.style.fontSize!=""){
 						styleStr=styleStr+"font-size:"+content.style.fontSize+";";
 					}
 					if(content.style.fontWeight!=""){
 						styleStr=styleStr+"font-weight:"+content.style.fontWeight+";";
 					}
 					if(content.style.fontStyle!=""){
 						styleStr=styleStr+"font-style:"+content.style.fontStyle+";";
 					}
 					if(content.style.textDecoration!=""){
 						styleStr=styleStr+"text-decoration:"+content.style.textDecoration+";";
 					}
 					if(content.style.color!=""){
 						styleStr=styleStr+"color:"+content.style.color+";";
 					}
 					if(content.style.backgroundColor!=""){
 						styleStr=styleStr+"background-color:"+content.style.backgroundColor+";";
 					}
 					return styleStr;
				 };
				 
				 
				 //取消超链接
				 $scope.cancelHref=function(){
					 var text=window.getSelection?window.getSelection().toString():(document.getSelection?document.getSelection():(document.selection?document.selection.createRange().text:""));
					 if(text!=""){
						 var contentChild=new Array();
						 if(window.getSelection().anchorNode.parentNode.tagName=="A"||window.getSelection().anchorNode.parentNode.tagName=="SPAN"){
							 contentChild=window.getSelection().anchorNode.parentNode.parentNode.childNodes;
						 }else{
							 contentChild=window.getSelection().anchorNode.parentNode.childNodes;
						 }
						 var star = window.getSelection().anchorOffset;
			             var end = window.getSelection().focusOffset;
						//ie浏览器，把起始点为最前面的，会获取为外面父节点
				        if(window.getSelection().anchorNode.tagName=="P"
				        		||window.getSelection().anchorNode.tagName=="H1"
				        			||window.getSelection().anchorNode.tagName=="H2"||window.getSelection().anchorNode.tagName=="H3"){
				        	contentChild=window.getSelection().anchorNode.childNodes;
				        }
						 var selectAnchorNode = window.getSelection().anchorNode;
			             if(window.getSelection().anchorNode.parentNode.tagName=="A"||window.getSelection().anchorNode.parentNode.tagName=="SPAN"){
			                selectAnchorNode = window.getSelection().anchorNode.parentNode;
			             }
			           //ie浏览器，把起始点为最前面的，会获取为外面父节点
				        if((window.getSelection().anchorNode.tagName=="P"
				        		||window.getSelection().anchorNode.tagName=="H1"
				        			||window.getSelection().anchorNode.tagName=="H2"||window.getSelection().anchorNode.tagName=="H3")&&window.getSelection().anchorOffset==0){
				        		selectAnchorNode=contentChild[0];
				        		star=0;
				        }
				      //ie浏览器，把起始点为最前面的，会获取为外面父节点
				        if((window.getSelection().anchorNode.tagName=="P"
				        		||window.getSelection().anchorNode.tagName=="H1"
				        			||window.getSelection().anchorNode.tagName=="H2"||window.getSelection().anchorNode.tagName=="H3")&&window.getSelection().anchorOffset!=0){
				        		selectAnchorNode=contentChild[contentChild.length-1];
				        		end=contentChild[contentChild.length-1].textContent.length;
				        }
			             var selectFocusNode = window.getSelection().focusNode;
			             if(window.getSelection().focusNode.parentNode.tagName=="A"||window.getSelection().focusNode.parentNode.tagName=="SPAN"){
			                selectFocusNode = window.getSelection().focusNode.parentNode;
			             }
			           //ie浏览器，把结束点为最后面的，会获取为外面父节点
					        if((window.getSelection().focusNode.tagName=="P"
					        		||window.getSelection().focusNode.tagName=="H1"
					        			||window.getSelection().focusNode.tagName=="H2"||window.getSelection().focusNode.tagName=="H3")&&window.getSelection().focusOffset==0){
					        	selectFocusNode=contentChild[0];
					        	star=0;
					        }
					      //ie浏览器，把结束点为最后面的，会获取为外面父节点
					        if((window.getSelection().focusNode.tagName=="P"
					        		||window.getSelection().focusNode.tagName=="H1"
					        			||window.getSelection().focusNode.tagName=="H2"||window.getSelection().focusNode.tagName=="H3")&&window.getSelection().focusOffset!=0){
					        	selectFocusNode=contentChild[contentChild.length-1];
					        	end=contentChild[contentChild.length-1].textContent.length;
					        }
			             var starNode=0;
			             var endNode=0;
			             
						 for(var i=0;i<contentChild.length;i++){
							 if(selectAnchorNode==contentChild[i]){
								 starNode = i;
							 }
							 if(selectFocusNode==contentChild[i]){
								 endNode = i;
							 }
			              }
						 if(starNode==endNode&&selectAnchorNode.tagName!="A"){
							 return ;
						 }
						 if(starNode>endNode){
							 var t=endNode;
							 endNode=starNode;
							 starNode=t; 
							 var s=end;
							 end=star;
							 star=s;
							 var f=selectAnchorNode;
							 selectAnchorNode=selectFocusNode;
							 selectFocusNode=f;
						 }
						 
						 if(starNode==endNode&&star>end){
							 var s=end;
							 end=star;
							 star=s;
						 }
						 
						 var stringToStart="";
						 for(var i=0;i<starNode;i++){
							 if(contentChild[i].length){
								 stringToStart=stringToStart+contentChild[i].textContent;
					 		}else{
					 			stringToStart=stringToStart+contentChild[i].outerHTML;
					 		}
							 
						 }
						 var stringToEnd="";
						 if(endNode!=(contentChild.length-1)){
							 for(var i=(endNode+1);i<contentChild.length;i++){
								 if(contentChild[i].length){
									 stringToEnd=stringToEnd+contentChild[i].textContent;
						 		}else{
						 			stringToEnd=stringToEnd+contentChild[i].outerHTML;
						 		}
							 }
						 }
						 var centerText="";
						 for(var i=starNode;i<endNode+1;i++){
							 if(i==starNode&&i==endNode){
								 if(contentChild[i].length){
									 centerText=centerText+selectAnchorNode.textContent.substring(star,end);
						 		}else{
						 			var styleStr=$scope.styleStr(selectAnchorNode);
						 			if(styleStr!=""){
						 				centerText=centerText+"<span style='"+styleStr+"'>"+selectAnchorNode.textContent.substring(star,end)+"</span>";
						 			}else{
						 				centerText=centerText+"<span>"+selectAnchorNode.textContent.substring(star,end)+"</span>";
						 			}
						 			
						 		}
							 }else if(i==starNode){
								 if(selectAnchorNode.textContent.substring(star)!=""){
									 if(contentChild[i].length){
										 centerText=centerText+selectAnchorNode.textContent.substring(star);
							 		}else{
							 			var styleStr=$scope.styleStr(selectAnchorNode);
							 			if(styleStr!=""){
							 				centerText=centerText+"<span style='"+styleStr+"'>"+selectAnchorNode.textContent.substring(star)+"</span>";
							 			}else{
							 				centerText=centerText+"<span>"+selectAnchorNode.textContent.substring(star)+"</span>";
							 			}
							 			
							 		}
								 } 
							 }else if(i==endNode){
								 if(selectFocusNode.textContent.substring(0,end)!=""){
									 if(contentChild[i].length){
										 centerText=centerText+selectFocusNode.textContent.substring(0,end);
							 		}else{
							 			var styleStr=$scope.styleStr(selectFocusNode);
							 			if(styleStr!=""){
							 				centerText=centerText+"<span style='"+styleStr+"'>"+selectFocusNode.textContent.substring(0,end)+"</span>";
							 			}else{
							 				centerText=centerText+"<span>"+selectFocusNode.textContent.substring(0,end)+"</span>";
							 			}
							 			
							 		}
								 }
								 
							 }else{
								 if((contentChild[i].tagName=="SPAN"||contentChild[i].tagName=="A")&&contentChild[i].textContent==""){
								 		
								 }else if(contentChild[i].tagName=="BR"){
									 centerText=centerText+contentChild[i].outerHTML;
								 }else{
									 if(contentChild[i].length){
										 centerText=centerText+contentChild[i].textContent;
								 	}else{
								 		var styleStr=$scope.styleStr(contentChild[i]);
							 			if(styleStr!=""){
							 				centerText=centerText+"<span style='"+styleStr+"'>"+contentChild[i].textContent+"</span>";
							 			}else{
							 				centerText=centerText+"<span>"+contentChild[i].textContent+"</span>";
							 			}
								 		
								 	}
								 }
								 
							 }
						 }
						 
						 var startA="";
						 if(selectAnchorNode.tagName=="A"){
							 if(selectAnchorNode.textContent.substring(0,star)!=""){
								 if(star!=0){
									 if(selectAnchorNode.className.indexOf("inCode")>0){
										 var styleStr=$scope.styleStr(selectAnchorNode);
								 			if(styleStr!=""){
								 				startA="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
								 			}else{
								 				startA="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
								 			}
										 
									 }else if(selectAnchorNode.className.indexOf("outCode")>0){
										 var styleStr=$scope.styleStr(selectAnchorNode);
								 			if(styleStr!=""){
								 				startA="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
								 			}else{
								 				startA="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
								 			}
										 
									 }else{
										 var styleStr=$scope.styleStr(selectAnchorNode);
								 			if(styleStr!=""){
								 				startA="<a href='"+selectAnchorNode.href+"' style='"+styleStr+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
								 			}else{
								 				startA="<a href='"+selectAnchorNode.href+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
								 			}
										 
									 }
									 
									 
								 }
							 }
							 
						 }else if(selectAnchorNode.tagName=="SPAN"){
							 if(selectAnchorNode.textContent.substring(0,star)!=""){
								 if(star!=0){
									 var styleStr=$scope.styleStr(selectAnchorNode);
							 			if(styleStr!=""){
							 				startA="<span style='"+styleStr+"'>"+selectAnchorNode.textContent.substring(0,star)+"</span>";
							 			}else{
							 				startA="<span>"+selectAnchorNode.textContent.substring(0,star)+"</span>";
							 			}
										
										 
									 }
							 }
							 
						 }else{
							 if(selectAnchorNode.textContent.substring(0,star)!=""){
								 startA=selectAnchorNode.textContent.substring(0,star);
							 }
							 
						 }
						 var endA="";
						 if(selectFocusNode.tagName=="A"){
							 if(selectFocusNode.textContent.substring(end)!=""){
								 if(end!=selectFocusNode.textContent.length){
									 if(selectFocusNode.className.indexOf("inCode")>0){
										 var styleStr=$scope.styleStr(selectFocusNode);
								 			if(styleStr!=""){
								 				endA="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"' style='"+styleStr+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
								 			}else{
								 				endA="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
								 			}
										 
									 }else if(selectFocusNode.className.indexOf("outCode")>0){
										 var styleStr=$scope.styleStr(selectFocusNode);
								 			if(styleStr!=""){
								 				endA="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"' style='"+styleStr+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
								 			}else{
								 				endA="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
								 			}
										 
									 }else{
										 var styleStr=$scope.styleStr(selectFocusNode);
								 			if(styleStr!=""){
								 				endA="<a href='"+selectFocusNode.href+"' style='"+styleStr+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
								 			}else{
								 				endA="<a href='"+selectFocusNode.href+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
								 			}
										 
									 }
									 
								 }
							 }
							 
						 }else if(selectFocusNode.tagName=="SPAN"){
							 if(selectFocusNode.textContent.substring(end)!=""){
								 if(end!=selectFocusNode.textContent.length){
									 var styleStr=$scope.styleStr(selectFocusNode);
							 			if(styleStr!=""){
							 				endA="<span style='"+styleStr+"'>"+selectFocusNode.textContent.substring(end)+"</span>";
							 			}else{
							 				endA="<span>"+selectFocusNode.textContent.substring(end)+"</span>";
							 			}
										
									 }
							 }
							 
						 }else{
							 if(selectFocusNode.textContent.substring(end)!=""){
								 endA=selectFocusNode.textContent.substring(end);
							 }
							 
						 }
						 
						 $scope.allElements[$scope.checkedItemId].content = stringToStart + startA+centerText+endA + stringToEnd ;
						 $scope.urlFlag=true;
						 $scope.currentUrl="";
						 $scope.currentUrlType="No";
						 $scope.currentUrlNodeId=""; 
						 window.getSelection().removeAllRanges();
					 }
				 };
				 
				 
				 //保存元素
				 $scope.autoNumber=0;
				 $scope.saveElements=function(){
					/* var titleObj=$("<div style='border-bottom:1px solid #ccc;'>"+opts.title+"</div>");
					 $("#elementShowFrame").contents().find("body").find("#contentDiv").append(titleObj);*/
					 $("#elementShowFrame").contents().find("body").find("#contentDiv")[0].style.marginTop=$scope.page.marginTop;
					 $("#elementShowFrame").contents().find("body").find("#contentDiv")[0].style.marginBottom=$scope.page.marginBottom;
					 $("#elementShowFrame").contents().find("body").find("#contentDiv")[0].style.marginLeft=$scope.page.marginLeft;
					 $("#elementShowFrame").contents().find("body").find("#contentDiv")[0].style.marginRight=$scope.page.marginRight;
					 for(var item in $scope.allElements){
						 
							var element=$scope.allElements[item];
							var obj=$("<div></div>");
							if(element.type=="title"&&element.fontSizeFlag=="1"){
								$scope.autoNumber=$scope.autoNumber+1;
								obj=$("<h1 style='text-align:"+element.textAlign+";word-wrap: break-word;margin-top:"
										+element.marginTop+";margin-bottom:"+element.marginBottom+";'>"+element.content+"</h1>");
							}else if(element.type=="title"&&element.fontSizeFlag=="2"){
								$scope.autoNumber=$scope.autoNumber+1;
								obj=$("<h2 style='text-align:"+element.textAlign+";word-wrap: break-word;margin-top:"
										+element.marginTop+";margin-bottom:"+element.marginBottom+";'>"+element.content+"</h2>");
							}else if(element.type=="title"&&element.fontSizeFlag=="3"){
								$scope.autoNumber=$scope.autoNumber+1;
								obj=$("<h3 style='text-align:"+element.textAlign+";word-wrap: break-word;margin-top:"
										+element.marginTop+";margin-bottom:"+element.marginBottom+";'>"+element.content+"</h3>");
							}else if(element.type=="content"){
								$scope.autoNumber=$scope.autoNumber+1;
								var textIndex="";
								if(element.textIndent!=""){
									textIndex="text-indent:"+element.textIndent+";";
								}
								if(element.backgroundImage==""){
									obj=$("<p style='text-align:"+element.textAlign+";word-wrap: break-word;font-size:"+element.fontSize+";margin-top:"
											+element.marginTop+";margin-bottom:"+element.marginBottom+";line-height:"+element.lineHeight+";"+textIndex+"'>"+element.content+"</p>");
								}else{
									obj=$("<p style='text-align:"+element.textAlign+";word-wrap: break-word;font-size:"+element.fontSize+";background-image:"+element.backgroundImage+";margin-top:"
											+element.marginTop+";margin-bottom:"+element.marginBottom+";line-height:"+element.lineHeight+";"+textIndex+"'>"+element.content+"</p>");
								}
								
							}else if(element.type=="image" && element.imagesSrc.length>0){

				            	if(element.imagesSrc.length<2){
				            		$scope.autoNumber=$scope.autoNumber+1;
				            		
				            		if(element.isClickChange=="Y"&&element.imagesSrc[0].href==""&&element.imagesSrc[0].path!=""){ //点击放大，无连接
				            			obj=$("<div style='text-align:center;margin-top:"
										+element.marginTop+";margin-bottom:"+element.marginBottom+";' onclick='picShow(\""+element.imagesSrc[0].path+"\",0)'><img src='"+element.imagesSrc[0].path+"' style='width:"+element.width+";height:"+element.height+";'/>" +
				            					"<span style='display:block;'>"+element.imagesSrc[0].title+"</span></div>");
				            		}else if(element.isClickChange=="N"&&element.imagesSrc[0].href==""&&element.imagesSrc[0].path!=""){ //不点击放大，无连接
				            			obj=$("<div style='text-align:center;margin-top:"
										+element.marginTop+";margin-bottom:"+element.marginBottom+";'>" +
												"<img src='"+element.imagesSrc[0].path+"' style='width:"+element.width+";height:"+element.height+";'/>" +
												"<span style='display:block;'>"+element.imagesSrc[0].title+"</span></div>");
				            		}else if(element.imagesSrc[0].href!=""&&element.imagesSrc[0].path!=""){ //有连接,只按照连接来，不管点击效果
				            			if(element.imagesSrc[0].hrefType=="In"){ //码内
											obj=$("<div style='text-align:center;margin-top:"
										+element.marginTop+";margin-bottom:"+element.marginBottom+";'><a href='"+element.imagesSrc[0].href+"' class='__resource__inCode__"+element.imagesSrc[0].hrefNodeId+"'>" +
													"<img class='__resource__image__"+$scope.autoNumber+"_loc' src='"+element.imagesSrc[0].path+"' " +
															"style='width:"+element.width+";height:"+element.height+"' /></a><span style='display:block;'>"+element.imagesSrc[0].title+"</span></div>");
										}else if(element.imagesSrc[0].hrefType=="Out"){ //码外
											obj=$("<div style='text-align:center;margin-top:"
										+element.marginTop+";margin-bottom:"+element.marginBottom+";'><a href='"+element.imagesSrc[0].href+"' class='__resource__outCode__"+element.imagesSrc[0].hrefNodeId+"'>" +
													"<img class='__resource__image__"+$scope.autoNumber+"_loc' src='"+element.imagesSrc[0].path+"' " +
															"style='width:"+element.width+";height:"+element.height+"' /></a><span style='display:block;'>"+element.imagesSrc[0].title+"</span></div>");
										}else{
											obj=$("<div style='text-align:center;margin-top:"
										+element.marginTop+";margin-bottom:"+element.marginBottom+";'><a href='"+element.imagesSrc[0].href+"'>" +
													"<img class='__resource__image__"+$scope.autoNumber+"_loc' src='"+element.imagesSrc[0].path+"' " +
															"style='width:"+element.width+";height:"+element.height+"' /></a><span style='display:block;'>"+element.imagesSrc[0].title+"</span></div>");
										}
				            		}
				            		var hiddenMsg=$("<input type='hidden' value='"+element.imagesSrc[0].path+"' class='__resource__image__"+$scope.autoNumber+"__src'>");
									$("#elementShowFrame").contents().find("body").find(".resourceDiv").append(hiddenMsg);
				            	}else if(element.isClickChange=="Y"){
									var div=$("<div class='ui-slider' style='width:"+element.width+";margin-top:"
										+element.marginTop+";margin-bottom:"+element.marginBottom+";'></div>");
									var ul=$("<ul class='ui-slider-content' style='width:"+element.imagesSrc.length+"00%;-webkit-padding-start:0px;-webkit-margin-before:0px;'></ul>");
									var pathStrs="";
									for(var i=0;i<element.imagesSrc.length;i++){
										if(i==0){
											pathStrs=element.imagesSrc[i].path;
										}else{
											pathStrs=pathStrs+","+element.imagesSrc[i].path;
										}
										
									}
									for(var i=0;i<element.imagesSrc.length;i++){
										if(element.imagesSrc[i].path!=""){
											$scope.autoNumber=$scope.autoNumber+1;
											if(element.imagesSrc[i].href!=""){
												var li=null;
												if(element.imagesSrc[i].hrefType=="In"){ //码内
													li=$("<li><span><a href='"+element.imagesSrc[i].href+"' class='__resource__inCode__"+element.imagesSrc[i].hrefNodeId+"'><img class='__resource__image__"+$scope.autoNumber+"_loc' src='"+element.imagesSrc[i].path+"' " +
																	"style='width:"+element.width+";height:"+element.height+"' /></a></span>" +
																			"<span>"+element.imagesSrc[i].title+"</span></li>");
												}else if(element.imagesSrc[i].hrefType=="Out"){ //码外
													li=$("<li><span><a href='"+element.imagesSrc[i].href+"' class='__resource__outCode__"+element.imagesSrc[i].hrefNodeId+"'><img class='__resource__image__"+$scope.autoNumber+"_loc' src='"+element.imagesSrc[i].path+"' " +
																	"style='width:"+element.width+";height:"+element.height+"' /></a></span>" +
																			"<span>"+element.imagesSrc[i].title+"</span></li>");
												}else{
													li=$("<li><span><a href='"+element.imagesSrc[i].href+"'><img class='__resource__image__"+$scope.autoNumber+"_loc' src='"+element.imagesSrc[i].path+"' " +
																	"style='width:"+element.width+";height:"+element.height+"' /></a></span>" +
																			"<span>"+element.imagesSrc[i].title+"</span></li>");
												}
												ul.append(li);
											}else{
												var li=$("<li onclick='picShow(\""+pathStrs+"\","+i+")'><span>" +
														"<img class='__resource__image__"+$scope.autoNumber+"_loc' src='"+element.imagesSrc[i].path+"' " +
																"style='width:"+element.width+";height:"+element.height+";' /></span>" +
																"<span>"+element.imagesSrc[i].title+"</span></li>");
												ul.append(li);
											}
											var hiddenMsg=$("<input type='hidden' value='"+element.imagesSrc[i].path+"' class='__resource__image__"+$scope.autoNumber+"__src'>");
											$("#elementShowFrame").contents().find("body").find(".resourceDiv").append(hiddenMsg);
										}
									}
									var menuDiv=$("<div class='icons' style='position:absolute;bottom:30px;right:0px;'></div>");
									for(var i=0;i<element.imagesSrc.length;i++){
										if(i==0){
											var span=$("<span class='curr'>1</span>");
											menuDiv.append(span);
										}else{
											var span=$("<span>"+(i+1)+"</span>");
											menuDiv.append(span);
										}
										
									}
									div.append(ul);
									div.append(menuDiv);
									obj=div;
									
								}else if(element.isClickChange=="N"){
									var div=$("<div class='ui-slider' style='width:"+element.width+";margin-top:"
										+element.marginTop+";margin-bottom:"+element.marginBottom+";'></div>");
									var ul=$("<ul class='ui-slider-content' style='width:"+element.imagesSrc.length+"00%;-webkit-padding-start:0px;-webkit-margin-before:0px;'></ul>");
									for(var i=0;i<element.imagesSrc.length;i++){
										if(element.imagesSrc[i].path!=""){
											$scope.autoNumber=$scope.autoNumber+1;
											if(element.imagesSrc[i].href!=""){
												var li=null;
												if(element.imagesSrc[i].hrefType=="In"){ //码内
													li=$("<li><span><a href='"+element.imagesSrc[i].href+"' class='__resource__inCode__"+element.imagesSrc[i].hrefNodeId+"'><img class='__resource__image__"+$scope.autoNumber+"_loc' src='"+element.imagesSrc[i].path+"' " +
																	"style='width:"+element.width+";height:"+element.height+"' /></a></span>" +
																			"<span>"+element.imagesSrc[i].title+"</span></li>");
												}else if(element.imagesSrc[i].hrefType=="Out"){ //码外
													li=$("<li><span><a href='"+element.imagesSrc[i].href+"' class='__resource__outCode__"+element.imagesSrc[i].hrefNodeId+"'><img class='__resource__image__"+$scope.autoNumber+"_loc' src='"+element.imagesSrc[i].path+"' " +
																	"style='width:"+element.width+";height:"+element.height+"' /></a></span>" +
																			"<span>"+element.imagesSrc[i].title+"</span></li>");
												}else{
													li=$("<li><span><a href='"+element.imagesSrc[i].href+"'><img class='__resource__image__"+$scope.autoNumber+"_loc' src='"+element.imagesSrc[i].path+"' " +
																	"style='width:"+element.width+";height:"+element.height+"' /></a></span>" +
																			"<span>"+element.imagesSrc[i].title+"</span></li>");
												}
												ul.append(li);
											}else{
												var li=$("<li><span>" +
														"<img class='__resource__image__"+$scope.autoNumber+"_loc' src='"+element.imagesSrc[i].path+"' " +
																"style='width:"+element.width+";height:"+element.height+";' /></span>" +
																"<span>"+element.imagesSrc[i].title+"</span></li>");
												ul.append(li);
											}
											var hiddenMsg=$("<input type='hidden' value='"+element.imagesSrc[i].path+"' class='__resource__image__"+$scope.autoNumber+"__src'>");
											$("#elementShowFrame").contents().find("body").find(".resourceDiv").append(hiddenMsg);
										}
										
									}
									var menuDiv=$("<div class='icons' style='position:absolute;bottom:30px;right:0px;'></div>");
									for(var i=0;i<element.imagesSrc.length;i++){
										if(i==0){
											var span=$("<span class='curr'>1</span>");
											menuDiv.append(span);
										}else{
											var span=$("<span>"+(i+1)+"</span>");
											menuDiv.append(span);
										}
										
									}
									div.append(ul);
									div.append(menuDiv);
									obj=div;
								}
								
								
							}else if(element.type=="audio"){
								$scope.autoNumber=$scope.autoNumber+1;
				    			
				    				var divObj=$("<div style='position:relative;margin-top:"
										+element.marginTop+";margin-bottom:"+element.marginBottom+";' " +
												"onclick='audioShow(this,\""+element.src+"\",\""+element.audioCoverImg+"\",\"\")'></div>");
	
				    				var imgObj=$("<img src='"+$scope.picPath+"images/audio.png' style='width:150px;' />");
				    				var h3Obj=$("<h3 style='border-top:2px solid #666;color:orange;margin-top:0px;'>"+element.audioTitle+"</h3>");
				    				var imgObj1=$("<img src='"+$scope.picPath+"images/btn_sound_nor.png' style='position:absolute;top:15px;right:0px;width:30px;' />");
				    				var content=element.audioContent.replace(/\n/g,"<BR>");
				    				$scope.allElements[item].audioContent=content;
				    				var spanObj=$("<span style='display:none;'>"+content+"</span>");
				    				divObj.append(imgObj);
				    				divObj.append(h3Obj);
				    				divObj.append(imgObj1);
				    				divObj.append(spanObj);
				    				obj=divObj;
				    			/*}else{
				    				obj=$("<audio class='__resource__audio__"+$scope.autoNumber+"__loc' src='"+element.src+"' controls='controls' preload = none></audio>");
				    			}*/
				    				
								var hiddenMsg=$("<input type='hidden' value='"+element.src+"' class='__resource__audio__"+$scope.autoNumber+"__src'>");
								$("#elementShowFrame").contents().find("body").find(".resourceDiv").append(hiddenMsg);
								var hiddenMsgImg=$("<input type='hidden' value='"+element.audioCoverImg+"' >");
								$("#elementShowFrame").contents().find("body").find(".resourceDiv").append(hiddenMsgImg);
							}else if(element.type=="video"){
								$scope.autoNumber=$scope.autoNumber+1;
								var coverImgTemp="";
								if(element.coverImg==""){
									coverImgTemp=$scope.picPath+"images/unknown.jpg";
								}else{
									coverImgTemp=element.coverImg;
								}
								obj=$("<div style='position:relative;margin-top:"
										+element.marginTop+";margin-bottom:"+element.marginBottom+";'>" +
										"<table class='otherVideo' style='display:none;'>" +
										"<tr>" +
										"<td rowspan='2'><img style='width:100px;' src='"+coverImgTemp+"' onclick='videoPlay(this)'>" +
										"<video style='width:100%;display:none;' preload='none' controls='controls' class='__resource__video__"+$scope.autoNumber+"__loc'>" +
										"<source src='"+element.src+"' type='video/mp4'>" +
										"<source src='"+element.src+"' type='video/ogg'>" +
										"<source src='"+element.src+"' type='video/webm'>" +
										"</video><input type='hidden' value='"+element.videoTitle+"'></td>" +
										"<td style='height:30px'><img style='width:150px;' src='"+$scope.picPath+"images/pic_top_three.png'></td>" +
										"</tr>" +
										"<tr>" +
										"<td style='vertical-align:baseline;color:orange;'>"+element.videoTitle+"</td>" +
										"</tr>" +
										"</table>" +
										"<video class='androidVideo ' style='width:100%;display:none;' preload='none' controls='controls' poster='"+coverImgTemp+"'>" +
										"<source src='"+element.src+"' type='video/mp4'>" +
										"<source src='"+element.src+"' type='video/ogg'>" +
										"<source src='"+element.src+"' type='video/webm'>" +
										"</video>" +
										"</div>");
								
								
								
								/*obj=$("<div style='text-align:center;margin-top:"
										+element.marginTop+";margin-bottom:"+element.marginBottom+";'><video  class='__resource__video__"+$scope.autoNumber+"__loc' controls " +
										"width='100%' poster='"+element.coverImg+"'>" +
												"<source src='"+element.src+"' type='video/mp4'>" +
												"<source src='"+element.src+"' type='video/ogg'>" +
												"Your browser does not support the video tag.</video><span>"+element.videoTitle+"</span></div>");*/
								
								var hiddenMsg=$("<input type='hidden' value='"+element.src+"' class='__resource__video__"+$scope.autoNumber+"__src'>");
								$("#elementShowFrame").contents().find("body").find(".resourceDiv").append(hiddenMsg);
								var hiddenMsgImg=$("<input type='hidden' value='"+element.coverImg+"'>");
								$("#elementShowFrame").contents().find("body").find(".resourceDiv").append(hiddenMsgImg);
							}else if(element.type=="pdf"){
								$scope.autoNumber=$scope.autoNumber+1;
								
								obj=$("<div style='position:relative;margin-top:"
										+element.marginTop+";margin-bottom:"+element.marginBottom+";' class='__resource__pdf__"+$scope.autoNumber+"_loc' onclick='pdfShow(\""+element.src+"\")'>" +
										"<img src='"+$scope.picPath+"images/read.png' style='width:190px;'>" +
										"<h3 style='border-top:2px solid #666;color:orange;margin-top:0px;'>"+element.title+"</h3>" +
												"<img src='"+$scope.picPath+"images/btn_book_nor.png' " +
												"style='position:absolute;top:15px;right:0px;width:30px;'></div>");
								var hiddenMsg=$("<input type='hidden' value='"+element.src+"' class='__resource__pdf__"+$scope.autoNumber+"__src'>");
								$("#elementShowFrame").contents().find("body").find(".resourceDiv").append(hiddenMsg);
								
							}else if(element.type=="word"){
								$scope.autoNumber=$scope.autoNumber+1;
								
								obj=$("<div style='position:relative;margin-top:"
										+element.marginTop+";margin-bottom:"+element.marginBottom+";' class='__resource__word__"+$scope.autoNumber+"_loc' onclick='wordShow(\""+element.src+"\")'>" +
										"<img src='"+$scope.picPath+"images/bg_other_element.png' style='width:190px;'>" +
										"<h3 style='border-top:2px solid #666;color:orange;margin-top:0px;'>"+element.title+"</h3>" +
												"<img src='"+$scope.picPath+"images/icon_other_element.png' " +
												"style='position:absolute;top:15px;right:0px;width:30px;'></div>");
								var hiddenMsg=$("<input type='hidden' value='"+element.src+"' class='__resource__word__"+$scope.autoNumber+"__src'>");
								$("#elementShowFrame").contents().find("body").find(".resourceDiv").append(hiddenMsg);
							}else if(element.type=="accessory"){
								$scope.autoNumber=$scope.autoNumber+1;
								
								obj=$("<div style='position:relative;margin-top:"
										+element.marginTop+";margin-bottom:"+element.marginBottom+";' class='__resource__other__"+$scope.autoNumber+"_loc' onclick='qtShow(\""+element.src+"\")'>" +
										"<img src='"+$scope.picPath+"images/bg_other_element.png' style='width:190px;'>" +
										"<h3 style='border-top:2px solid #666;color:orange;margin-top:0px;'>"+element.title+"</h3>" +
												"<img src='"+$scope.picPath+"images/icon_other_element.png' " +
												"style='position:absolute;top:15px;right:0px;width:30px;'></div>");
								
							}	
							
							
							$("#elementShowFrame").contents().find("body").find("#contentDiv").append(obj);
						}
					 $("#elementShowFrame").contents().find("body").find("._resource_loaclPath").val(localPath);
					 $("#elementShowFrame").contents().find("head").append("<title>"+opts.title+"</title>");
					 var iframeObj=document.getElementById("elementShowFrame").contentWindow.document.documentElement.outerHTML;
					 
					 iframeObj=iframeObj.replace("../images/goDown.png",$scope.picPath+"images/goDown.png");
					 iframeObj=iframeObj.replace("../images/goUp.png",$scope.picPath+"images/goUp.png");
					 iframeObj=iframeObj.replace("../images/audioShow.gif",$scope.picPath+"images/audioShow.gif");
					 iframeObj=iframeObj.replace("../images/jt.png",$scope.picPath+"images/jt.png");
					 iframeObj=iframeObj.replace(/audioPause.png/g,$scope.picPath+"images/audioPause.png");
					 iframeObj=iframeObj.replace(/audioPlay.png/g,$scope.picPath+"images/audioPlay.png");
					 iframeObj=iframeObj.replace("../elementShow.css",$scope.picPath+"elementShow.css");
					 //iframeObj=iframeObj.replace("../elementShow.css","http://128.0.4.218:8080/ssk-sdjj/resource/res/libs/textEditor/elementShow.css");
					 iframeObj=iframeObj.replace("../js/elementShow.js",$scope.picPath+"js/elementShow.js");
					 //iframeObj=iframeObj.replace("../js/elementShow.js","http://128.0.4.218:8080/ssk-sdjj/resource/res/libs/textEditor/js/elementShow.js");
					 iframeObj=iframeObj.replace("../images/down_message.png",$scope.picPath+"images/down_message.png");
					 
					 //var dss= angular.toJson($scope.elementArr);
					//console.log(dss);
					 // var data = angular.toJson($scope);
					// iframeObj=iframeObj+"<!--"+data+"-->";
					
					var result={elementIndex:$scope.index,content:$scope.elementArr,page:$scope.page};
					var resultStr=JSON.stringify(result);
					if($scope.elementArr.length<1){
						opts.backFn("","");
					}else{
						opts.backFn(iframeObj,resultStr);
					}
					 
					
					
					 //console.log(iframeObj);
					 $scope.closeEditor();
				 };
				 
				 
				 $scope.closeEditor=function(){
					 opts.win.panel('close');
				 };
				 
				 
				 //字体加粗
				 $scope.fontWeight=function(){
					 var text=window.getSelection?window.getSelection().toString():(document.getSelection?document.getSelection():(document.selection?document.selection.createRange().text:""));
					 if(text!=""){
						 var contentChild=new Array();
						 if(window.getSelection().anchorNode.parentNode.tagName=="A"
							 ||window.getSelection().anchorNode.parentNode.tagName=="SPAN"){
							 contentChild=window.getSelection().anchorNode.parentNode.parentNode.childNodes;
						 }else{
							 contentChild=window.getSelection().anchorNode.parentNode.childNodes;
						 }
						 var star = window.getSelection().anchorOffset;
			             var end = window.getSelection().focusOffset;
						//ie浏览器，把起始点为最前面的，会获取为外面父节点
				        	if(window.getSelection().anchorNode.tagName=="P"
				        		||window.getSelection().anchorNode.tagName=="H1"
				        			||window.getSelection().anchorNode.tagName=="H2"||window.getSelection().anchorNode.tagName=="H3"){
				        		contentChild=window.getSelection().anchorNode.childNodes;
				        	}
						 var selectAnchorNode = window.getSelection().anchorNode;
			             if(window.getSelection().anchorNode.parentNode.tagName=="A"
			            	 ||window.getSelection().anchorNode.parentNode.tagName=="SPAN"){
			                selectAnchorNode = window.getSelection().anchorNode.parentNode;
			             }
			           //ie浏览器，把起始点为最前面的，会获取为外面父节点
				        	if((window.getSelection().anchorNode.tagName=="P"
				        		||window.getSelection().anchorNode.tagName=="H1"
				        			||window.getSelection().anchorNode.tagName=="H2"||window.getSelection().anchorNode.tagName=="H3")&&window.getSelection().anchorOffset==0){
				        		selectAnchorNode=contentChild[0];
				        		star=0;
				        	}
				        	//ie浏览器，把起始点为最前面的，会获取为外面父节点
				        	if((window.getSelection().anchorNode.tagName=="P"
				        		||window.getSelection().anchorNode.tagName=="H1"
				        			||window.getSelection().anchorNode.tagName=="H2"||window.getSelection().anchorNode.tagName=="H3")&&window.getSelection().anchorOffset!=0){
				        		selectAnchorNode=contentChild[contentChild.length-1];
				        		end=contentChild[contentChild.length-1].textContent.length;
				        	}
			             var selectFocusNode = window.getSelection().focusNode;
			             if(window.getSelection().focusNode.parentNode.tagName=="A"
			            	 ||window.getSelection().focusNode.parentNode.tagName=="SPAN"){
			                selectFocusNode = window.getSelection().focusNode.parentNode;
			             }
			           //ie浏览器，把结束点为最后面的，会获取为外面父节点
					        if((window.getSelection().focusNode.tagName=="P"
					        		||window.getSelection().focusNode.tagName=="H1"
					        			||window.getSelection().focusNode.tagName=="H2"||window.getSelection().focusNode.tagName=="H3")&&window.getSelection().focusOffset==0){
					        	selectFocusNode=contentChild[0];
					        	star=0;
					        }
					      //ie浏览器，把结束点为最后面的，会获取为外面父节点
					        if((window.getSelection().focusNode.tagName=="P"
					        		||window.getSelection().focusNode.tagName=="H1"
					        			||window.getSelection().focusNode.tagName=="H2"||window.getSelection().focusNode.tagName=="H3")&&window.getSelection().focusOffset!=0){
					        	selectFocusNode=contentChild[contentChild.length-1];
					        	end=contentChild[contentChild.length-1].textContent.length;
					        }
			             var starNode=0;
			             var endNode=0;
			             
						 for(var i=0;i<contentChild.length;i++){
							 if(selectAnchorNode==contentChild[i]){
								 starNode = i;
							 }
							 if(selectFocusNode==contentChild[i]){
								 endNode = i;
							 }
			              }
						 
						 if(starNode>endNode){
							 var t=endNode;
							 endNode=starNode;
							 starNode=t; 
							 var s=end;
							 end=star;
							 star=s;
							 var f=selectAnchorNode;
							 selectAnchorNode=selectFocusNode;
							 selectFocusNode=f;
						 }
						 
						 if(starNode==endNode&&star>end){
							 var s=end;
							 end=star;
							 star=s;
						 }
						 
						 
						 
						 //当选中的是同一块,没有样式的
						 if((starNode==endNode&&selectAnchorNode.tagName!="A")
								 &&(starNode==endNode&&selectAnchorNode.tagName!="SPAN")){
							 
							 var stringToStartText="";
							 for(var i=0;i<starNode;i++){
								 if(contentChild[i].tagName=="SPAN"&&contentChild[i].textContent==""){
								 		
								 }else if(contentChild[i].tagName=="BR"){
									 stringToStartText=stringToStartText+contentChild[i].outerHTML;
								 }else{
									 if(contentChild[i].length){
										 stringToStartText=stringToStartText+contentChild[i].textContent;
									 }else{
										 stringToStartText=stringToStartText+contentChild[i].outerHTML;
									 }
								 }
							 }
							 var stringToEndText="";
							 if(endNode!=(contentChild.length-1)){
								 for(var i=(endNode+1);i<contentChild.length;i++){
									 if(contentChild[i].tagName=="SPAN"&&contentChild[i].textContent==""){
									 		
									 }else if(contentChild[i].tagName=="BR"){
										 stringToEndText=stringToEndText+contentChild[i].outerHTML;
									 }else{
										 if(contentChild[i].length){
											 stringToEndText=stringToEndText+contentChild[i].textContent;
										 }else{
											 stringToEndText=stringToEndText+contentChild[i].outerHTML;
										 }
									 }
								 }
							 } 
							 var startText=selectAnchorNode.textContent.substring(0,star);
							 var endText=selectFocusNode.textContent.substring(end);
							 var centerText="<span style='font-weight:bold;'>"+text+"</span>";
							 $scope.allElements[$scope.checkedItemId].content = stringToStartText+startText + centerText+endText+stringToEndText;
							 $scope.urlFlag=true;
							 return ;
						 }
						 
						 
						 
						 var stringToStart="";
						 for(var i=0;i<starNode;i++){
							 if(contentChild[i].tagName=="SPAN"&&contentChild[i].textContent==""){
							 		
							 }else if(contentChild[i].tagName=="BR"){
								 stringToStart=stringToStart+contentChild[i].outerHTML;
							 }else{
								 if(contentChild[i].length){
								 
									 stringToStart=stringToStart+contentChild[i].textContent;
								 }else{
									 stringToStart=stringToStart+contentChild[i].outerHTML;
								 }
							 }
							 
						 }
						 var stringToEnd="";
						 if(endNode!=(contentChild.length-1)){
							 for(var i=(endNode+1);i<contentChild.length;i++){
								 if(contentChild[i].tagName=="SPAN"&&contentChild[i].textContent==""){
								 		
								 }else if(contentChild[i].tagName=="BR"){
									 stringToEnd=stringToEnd+contentChild[i].outerHTML;
								 }else{
									 if(contentChild[i].length){
										 stringToEnd=stringToEnd+contentChild[i].textContent;
									 }else{
										 stringToEnd=stringToEnd+contentChild[i].outerHTML;
									 }
								 }
							 }
						 }
						 var startA="";
						 if(selectAnchorNode.tagName=="A"){
							 if(star!=0){
								 if(selectAnchorNode.className.indexOf("inCode")>0){
									 var styleStr=$scope.styleStr(selectAnchorNode);
									 if(styleStr!=""){
										 startA="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
									 }else{
										 startA="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
									 }
									 
								 }else if(selectAnchorNode.className.indexOf("outCode")>0){
									 var styleStr=$scope.styleStr(selectAnchorNode);
									 if(styleStr!=""){
										 startA="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
									 }else{
										 startA="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
									 }
									 
								 }else{
									 var styleStr=$scope.styleStr(selectAnchorNode);
									 if(styleStr!=""){
										 startA="<a href='"+selectAnchorNode.href+"' style='"+styleStr+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
									 }else{
										 startA="<a href='"+selectAnchorNode.href+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
									 }
									 
								 }
								 
								 
							 }
						 }else if(selectAnchorNode.tagName=="SPAN"){
							 if(star!=0){
								 var styleStr=$scope.styleStr(selectAnchorNode);
								 if(styleStr!=""){
									 startA="<span style='"+styleStr+"'>"+selectAnchorNode.textContent.substring(0,star)+"</span>";
								 }else{
									 startA="<span>"+selectAnchorNode.textContent.substring(0,star)+"</span>";
								 }
								 
							 }
						 }else{
							 startA=selectAnchorNode.textContent.substring(0,star);
						 }
						 var endA="";
						 if(selectFocusNode.tagName=="A"){
							 if(end!=selectFocusNode.textContent.length){
								 if(selectFocusNode.className.indexOf("inCode")>0){
									 var styleStr=$scope.styleStr(selectFocusNode);
									 if(styleStr!=""){
										 endA="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"' style='"+styleStr+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
									 }else{
										 endA="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
									 }
									 
								 }else if(selectFocusNode.className.indexOf("outCode")>0){
									 var styleStr=$scope.styleStr(selectFocusNode);
									 if(styleStr!=""){
										 endA="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"' style='"+styleStr+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
									 }else{
										 endA="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
									 }
									 
								 }else{
									 var styleStr=$scope.styleStr(selectFocusNode);
									 if(styleStr!=""){
										 endA="<a href='"+selectFocusNode.href+"' style='"+styleStr+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
									 }else{
										 endA="<a href='"+selectFocusNode.href+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
									 }
									 
								 }
								 
							 }
						 }else if(selectFocusNode.tagName=="SPAN"){
							 if(end!=selectFocusNode.textContent.length){
								 var styleStr=$scope.styleStr(selectFocusNode);
								 if(styleStr!=""){
									 endA="<span style='"+styleStr+"'>"+selectFocusNode.textContent.substring(end)+"</span>";
								 }else{
									 endA="<span>"+selectFocusNode.textContent.substring(end)+"</span>";
								 }
								 
							 }
						 }else{
							 endA=selectFocusNode.textContent.substring(end);
						 }
						 
						 if(starNode==endNode){
							 if(selectAnchorNode.tagName=="A"){
								 if($scope.currentFontWeight){
									 var styleStr=$scope.styleChange(selectAnchorNode,"fontWeight");
									 
									 text="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"font-weight:normal;'>"+text+"</a>";
								 }else{
									 var styleStr=$scope.styleChange(selectAnchorNode,"fontWeight");
									 text="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"font-weight:bold;'>"+text+"</a>";
								 }
								 $scope.allElements[$scope.checkedItemId].content = stringToStart + startA+text+endA + stringToEnd ;
								 $scope.urlFlag=true;
							 }else if(selectAnchorNode.tagName=="SPAN"){
								 if($scope.currentFontWeight){
									 var styleStr=$scope.styleChange(selectAnchorNode,"fontWeight");
									 text="<span style='"+styleStr+"font-weight:normal;'>"+text+"</span>";
								 }else{
									 var styleStr=$scope.styleChange(selectAnchorNode,"fontWeight");
									 text="<span style='"+styleStr+"font-weight:bold;'>"+text+"</span>";
								 }
								 $scope.allElements[$scope.checkedItemId].content = stringToStart + startA+text+endA + stringToEnd ;
								 $scope.urlFlag=true;
							 }else{
								 text="<span style='font-weight:bold;'>"+text+"</span>";
								 $scope.allElements[$scope.checkedItemId].content = stringToStart + startA+text+endA + stringToEnd ;
								 $scope.urlFlag=true;
							 }
							 
						 }else{
							 var startText="";
							 if(selectAnchorNode.tagName=="A"){
								 if($scope.currentFontWeight){
									 var styleStr=$scope.styleChange(selectAnchorNode,"fontWeight");
									 startText="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"font-weight:normal;'>"+selectAnchorNode.textContent.substring(star)+"</a>";
								 }else{
									 var styleStr=$scope.styleChange(selectAnchorNode,"fontWeight");
									 startText="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"font-weight:bold;'>"+selectAnchorNode.textContent.substring(star)+"</a>";
								 }
							 }else if(selectAnchorNode.tagName=="SPAN"){
								 if($scope.currentFontWeight){
									 var styleStr=$scope.styleChange(selectAnchorNode,"fontWeight");
									 startText="<span style='"+styleStr+"font-weight:normal;'>"+selectAnchorNode.textContent.substring(star)+"</span>";
								 }else{
									 var styleStr=$scope.styleChange(selectAnchorNode,"fontWeight");
									 startText="<span style='"+styleStr+"font-weight:bold;'>"+selectAnchorNode.textContent.substring(star)+"</span>";
								 }
							 }else{
								 if($scope.currentFontWeight){
									 startText=selectAnchorNode.textContent.substring(star); 
								 }else{
									 startText="<span style='font-weight:bold;'>"+selectAnchorNode.textContent.substring(star)+"</span>";
								 }
								 
							 }
							 
							 var endText="";
							 if(selectFocusNode.tagName=="A"){
								 if($scope.currentFontWeight){
									 var styleStr=$scope.styleChange(selectFocusNode,"fontWeight");
									 endText="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"' style='"+styleStr+"font-weight:normal;'>"+selectFocusNode.textContent.substring(0,end)+"</a>";
								 }else{
									 var styleStr=$scope.styleChange(selectFocusNode,"fontWeight");
									 endText="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"' style='"+styleStr+"font-weight:bold;'>"+selectFocusNode.textContent.substring(0,end)+"</a>";
								 } 
								
							 }else if(selectFocusNode.tagName=="SPAN"){
								 if($scope.currentFontWeight){
									 var styleStr=$scope.styleChange(selectFocusNode,"fontWeight");
									 endText="<span style='"+styleStr+"font-weight:normal;'>"+selectFocusNode.textContent.substring(0,end)+"</span>";
								 }else{
									 var styleStr=$scope.styleChange(selectFocusNode,"fontWeight");
									 endText="<span style='"+styleStr+"font-weight:bold;'>"+selectFocusNode.textContent.substring(0,end)+"</span>";
								 }
							 }else{
								 if($scope.currentFontWeight){
									 endText=selectFocusNode.textContent.substring(0,end);
								 }else{
									 endText="<span style='font-weight:bold;'>"+selectFocusNode.textContent.substring(0,end)+"</span>";
								 }
								 
							 }
							 var centerText="";
								 for(var i=starNode+1;i<endNode;i++){
									 if(contentChild[i].tagName=="SPAN"&&contentChild[i].textContent==""){
									 		
									 }else if(contentChild[i].tagName=="BR"){
										 centerText=centerText+contentChild[i].outerHTML;
									 }else{
										 if(contentChild[i].length){
											 if($scope.currentFontWeight){
												 // contentChild[i].style.fontWeight="normal";
												 centerText=centerText+contentChild[i].textContent;
											 }else{
												 //contentChild[i].style.fontWeight="bold";
												 centerText=centerText+"<span style='font-weight:bold'>"+contentChild[i].textContent+"</span>";
											 }
										 
										 }else{
											 if($scope.currentFontWeight){
												 contentChild[i].style.fontWeight="normal";
											 }else{
												 contentChild[i].style.fontWeight="bold";
											 }
											 centerText=centerText+contentChild[i].outerHTML;
										 }
									 }
								 }
								 $scope.allElements[$scope.checkedItemId].content = stringToStart + startA+startText+centerText+endText+endA + stringToEnd ;
								 $scope.urlFlag=true;
						 }
						 
					 } 
					 
					 window.getSelection().removeAllRanges();
					 /*if($scope.allElements[$scope.checkedItemId].fontWeight==""){
						 $scope.allElements[$scope.checkedItemId].fontWeight="bold";
					 }else{
						 $scope.allElements[$scope.checkedItemId].fontWeight="";
					 }*/
					 
				 };
				 
				 //斜体
				 $scope.fontStyle=function(){
					 var text=window.getSelection?window.getSelection().toString():(document.getSelection?document.getSelection():(document.selection?document.selection.createRange().text:""));
					 if(text!=""){
						 var contentChild=new Array();
						 if(window.getSelection().anchorNode.parentNode.tagName=="A"
							 ||window.getSelection().anchorNode.parentNode.tagName=="SPAN"){
							 contentChild=window.getSelection().anchorNode.parentNode.parentNode.childNodes;
						 }else{
							 contentChild=window.getSelection().anchorNode.parentNode.childNodes;
						 }
						 var star = window.getSelection().anchorOffset;
			             var end = window.getSelection().focusOffset;
						//ie浏览器，把起始点为最前面的，会获取为外面父节点
				        	if(window.getSelection().anchorNode.tagName=="P"
				        		||window.getSelection().anchorNode.tagName=="H1"
				        			||window.getSelection().anchorNode.tagName=="H2"||window.getSelection().anchorNode.tagName=="H3"){
				        		contentChild=window.getSelection().anchorNode.childNodes;
				        	}
						 var selectAnchorNode = window.getSelection().anchorNode;
			             if(window.getSelection().anchorNode.parentNode.tagName=="A"
			            	 ||window.getSelection().anchorNode.parentNode.tagName=="SPAN"){
			                selectAnchorNode = window.getSelection().anchorNode.parentNode;
			             }
			           //ie浏览器，把起始点为最前面的，会获取为外面父节点
				        	if((window.getSelection().anchorNode.tagName=="P"
				        		||window.getSelection().anchorNode.tagName=="H1"
				        			||window.getSelection().anchorNode.tagName=="H2"||window.getSelection().anchorNode.tagName=="H3")&&window.getSelection().anchorOffset==0){
				        		selectAnchorNode=contentChild[0];
				        		star=0;
				        	}
				        	//ie浏览器，把起始点为最前面的，会获取为外面父节点
				        	if((window.getSelection().anchorNode.tagName=="P"
				        		||window.getSelection().anchorNode.tagName=="H1"
				        			||window.getSelection().anchorNode.tagName=="H2"||window.getSelection().anchorNode.tagName=="H3")&&window.getSelection().anchorOffset!=0){
				        		selectAnchorNode=contentChild[contentChild.length-1];
				        		end=contentChild[contentChild.length-1].textContent.length;
				        	}
			             var selectFocusNode = window.getSelection().focusNode;
			             if(window.getSelection().focusNode.parentNode.tagName=="A"
			            	 ||window.getSelection().focusNode.parentNode.tagName=="SPAN"){
			                selectFocusNode = window.getSelection().focusNode.parentNode;
			             }
			           //ie浏览器，把结束点为最后面的，会获取为外面父节点
					        if((window.getSelection().focusNode.tagName=="P"
					        		||window.getSelection().focusNode.tagName=="H1"
					        			||window.getSelection().focusNode.tagName=="H2"||window.getSelection().focusNode.tagName=="H3")&&window.getSelection().focusOffset==0){
					        	selectFocusNode=contentChild[0];
					        	star=0;
					        }
					      //ie浏览器，把结束点为最后面的，会获取为外面父节点
					        if((window.getSelection().focusNode.tagName=="P"
					        		||window.getSelection().focusNode.tagName=="H1"
					        			||window.getSelection().focusNode.tagName=="H2"||window.getSelection().focusNode.tagName=="H3")&&window.getSelection().focusOffset!=0){
					        	selectFocusNode=contentChild[contentChild.length-1];
					        	end=contentChild[contentChild.length-1].textContent.length;
					        }
			             var starNode=0;
			             var endNode=0;
			             
						 for(var i=0;i<contentChild.length;i++){
							 if(selectAnchorNode==contentChild[i]){
								 starNode = i;
							 }
							 if(selectFocusNode==contentChild[i]){
								 endNode = i;
							 }
			              }
						 
						 if(starNode>endNode){
							 var t=endNode;
							 endNode=starNode;
							 starNode=t; 
							 var s=end;
							 end=star;
							 star=s;
							 var f=selectAnchorNode;
							 selectAnchorNode=selectFocusNode;
							 selectFocusNode=f;
						 }
						 
						 if(starNode==endNode&&star>end){
							 var s=end;
							 end=star;
							 star=s;
						 }
						 
						 //当选中的是同一块,没有样式的
						 if((starNode==endNode&&selectAnchorNode.tagName!="A")
								 &&(starNode==endNode&&selectAnchorNode.tagName!="SPAN")){
							 
							 var stringToStartText="";
							 for(var i=0;i<starNode;i++){
								 if(contentChild[i].tagName=="SPAN"&&contentChild[i].textContent==""){
								 		
								 }else if(contentChild[i].tagName=="BR"){
									 stringToStartText=stringToStartText+contentChild[i].outerHTML;
								 }else{
									 if(contentChild[i].length){
										 stringToStartText=stringToStartText+contentChild[i].textContent;
									 }else{
										 stringToStartText=stringToStartText+contentChild[i].outerHTML;
									 }
								 }
							 }
							 var stringToEndText="";
							 if(endNode!=(contentChild.length-1)){
								 for(var i=(endNode+1);i<contentChild.length;i++){
									 if(contentChild[i].tagName=="SPAN"&&contentChild[i].textContent==""){
									 		
									 }else if(contentChild[i].tagName=="BR"){
										 stringToEndText=stringToEndText+contentChild[i].outerHTML;
									 }else{
										 if(contentChild[i].length){
											 stringToEndText=stringToEndText+contentChild[i].textContent;
										 }else{
											 stringToEndText=stringToEndText+contentChild[i].outerHTML;
										 }
									 }
								 }
							 } 
							 var startText=selectAnchorNode.textContent.substring(0,star);
							 var endText=selectAnchorNode.textContent.substring(end);
							 var centerText="<span style='font-style:italic;'>"+text+"</span>";
							 $scope.allElements[$scope.checkedItemId].content = stringToStartText+startText + centerText+endText+stringToEndText;
							 $scope.urlFlag=true;
							 return ;
						 }
						 
						 
						 
						 
						 var stringToStart="";
						 for(var i=0;i<starNode;i++){
							 if(contentChild[i].tagName=="SPAN"&&contentChild[i].textContent==""){
							 		
							 }else if(contentChild[i].tagName=="BR"){
								 stringToStart=stringToStart+contentChild[i].outerHTML;
							 }else{
								 if(contentChild[i].length){
								 
									 stringToStart=stringToStart+contentChild[i].textContent;
								 }else{
									 stringToStart=stringToStart+contentChild[i].outerHTML;
								 }
							 }
							 
						 }
						 var stringToEnd="";
						 if(endNode!=(contentChild.length-1)){
							 for(var i=(endNode+1);i<contentChild.length;i++){
								 if(contentChild[i].tagName=="SPAN"&&contentChild[i].textContent==""){
								 		
								 }else if(contentChild[i].tagName=="BR"){
									 stringToEnd=stringToEnd+contentChild[i].outerHTML;
								 }else{
									 if(contentChild[i].length){
										 stringToEnd=stringToEnd+contentChild[i].textContent;
									 }else{
										 stringToEnd=stringToEnd+contentChild[i].outerHTML;
									 }
								 }
							 }
						 }
						 var startA="";
						 if(selectAnchorNode.tagName=="A"){
							 if(star!=0){
								 if(selectAnchorNode.className.indexOf("inCode")>0){
									 var styleStr=$scope.styleStr(selectAnchorNode);
									 if(styleStr!=""){
										 startA="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
									 }else{
										 startA="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
									 }
									 
								 }else if(selectAnchorNode.className.indexOf("outCode")>0){
									 var styleStr=$scope.styleStr(selectAnchorNode);
									 if(styleStr!=""){
										 startA="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
									 }else{
										 startA="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
									 }
									 
								 }else{
									 var styleStr=$scope.styleStr(selectAnchorNode);
									 if(styleStr!=""){
										 startA="<a href='"+selectAnchorNode.href+"' style='"+styleStr+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
									 }else{
										 startA="<a href='"+selectAnchorNode.href+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
									 }
									 
								 }
								 
								 
							 }
						 }else if(selectAnchorNode.tagName=="SPAN"){
							 if(star!=0){
								 var styleStr=$scope.styleStr(selectAnchorNode);
								 if(styleStr!=""){
									 startA="<span style='"+styleStr+"'>"+selectAnchorNode.textContent.substring(0,star)+"</span>";
								 }else{
									 startA="<span>"+selectAnchorNode.textContent.substring(0,star)+"</span>";
								 }
								 
							 }
						 }else{
							 startA=selectAnchorNode.textContent.substring(0,star);
						 }
						 var endA="";
						 if(selectFocusNode.tagName=="A"){
							 if(end!=selectFocusNode.textContent.length){
								 if(selectFocusNode.className.indexOf("inCode")>0){
									 var styleStr=$scope.styleStr(selectFocusNode);
									 if(styleStr!=""){
										 endA="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"' style='"+styleStr+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
									 }else{
										 endA="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
									 }
									 
								 }else if(selectFocusNode.className.indexOf("outCode")>0){
									 var styleStr=$scope.styleStr(selectFocusNode);
									 if(styleStr!=""){
										 endA="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"' style='"+styleStr+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
									 }else{
										 endA="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
									 }
									 
								 }else{
									 var styleStr=$scope.styleStr(selectFocusNode);
									 if(styleStr!=""){
										 endA="<a href='"+selectFocusNode.href+"' style='"+styleStr+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
									 }else{
										 endA="<a href='"+selectFocusNode.href+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
									 }
									 
								 }
								 
							 }
						 }else if(selectFocusNode.tagName=="SPAN"){
							 if(end!=selectFocusNode.textContent.length){
								 var styleStr=$scope.styleStr(selectFocusNode);
								 if(styleStr!=""){
									 endA="<span style='"+styleStr+"'>"+selectFocusNode.textContent.substring(end)+"</span>";
								 }else{
									 endA="<span>"+selectFocusNode.textContent.substring(end)+"</span>";
								 }
								 
							 }
						 }else{
							 endA=selectFocusNode.textContent.substring(end);
						 }
						 
						 if(starNode==endNode){
							 if(selectAnchorNode.tagName=="A"){
								 if($scope.currentFontStyle){
									 var styleStr=$scope.styleChange(selectAnchorNode,"fontStyle");
									 text="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"font-style:normal;'>"+text+"</a>";
								 }else{
									 var styleStr=$scope.styleChange(selectAnchorNode,"fontStyle");
									 text="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"font-style:italic;'>"+text+"</a>";
								 }
								 $scope.allElements[$scope.checkedItemId].content = stringToStart + startA+text+endA + stringToEnd ;
								 $scope.urlFlag=true;
							 }else if(selectAnchorNode.tagName=="SPAN"){
								 if($scope.currentFontStyle){
									 var styleStr=$scope.styleChange(selectAnchorNode,"fontStyle");
									 text="<span style='"+styleStr+"font-style:normal;'>"+text+"</span>";
								 }else{
									 var styleStr=$scope.styleChange(selectAnchorNode,"fontStyle");
									 text="<span style='"+styleStr+"font-style:italic;'>"+text+"</span>";
								 }
								 $scope.allElements[$scope.checkedItemId].content = stringToStart + startA+text+endA + stringToEnd ;
								 $scope.urlFlag=true;
							 }else{
								 text="<span style='font-style:italic;'>"+text+"</span>";
								 $scope.allElements[$scope.checkedItemId].content = stringToStart + startA+text+endA + stringToEnd ;
								 $scope.urlFlag=true;
							 }
							 
						 }else{
							 var startText="";
							 if(selectAnchorNode.tagName=="A"){
								 if($scope.currentFontStyle){
									 var styleStr=$scope.styleChange(selectAnchorNode,"fontStyle");
									 startText="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"font-style:normal;'>"+selectAnchorNode.textContent.substring(star)+"</a>";
								 }else{
									 var styleStr=$scope.styleChange(selectAnchorNode,"fontStyle");
									 startText="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"font-style:italic;'>"+selectAnchorNode.textContent.substring(star)+"</a>";
								 }
							 }else if(selectAnchorNode.tagName=="SPAN"){
								 if($scope.currentFontStyle){
									 var styleStr=$scope.styleChange(selectAnchorNode,"fontStyle");
									 startText="<span style='"+styleStr+"font-style:normal;'>"+selectAnchorNode.textContent.substring(star)+"</span>";
								 }else{
									 var styleStr=$scope.styleChange(selectAnchorNode,"fontStyle");
									 startText="<span style='"+styleStr+"font-style:italic;'>"+selectAnchorNode.textContent.substring(star)+"</span>";
								 }
							 }else{
								 if($scope.currentFontStyle){
									 startText=selectAnchorNode.textContent.substring(star); 
								 }else{
									 startText="<span style='font-style:italic;'>"+selectAnchorNode.textContent.substring(star)+"</span>";
								 }
								 
							 }
							 
							 var endText="";
							 if(selectFocusNode.tagName=="A"){
								 if($scope.currentFontStyle){
									 var styleStr=$scope.styleChange(selectFocusNode,"fontStyle");
									 endText="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"' style='"+styleStr+"font-style:normal;'>"+selectFocusNode.textContent.substring(0,end)+"</a>";
								 }else{
									 var styleStr=$scope.styleChange(selectFocusNode,"fontStyle");
									 endText="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"' style='"+styleStr+"font-style:italic;'>"+selectFocusNode.textContent.substring(0,end)+"</a>";
								 } 
								
							 }else if(selectFocusNode.tagName=="SPAN"){
								 if($scope.currentFontStyle){
									 var styleStr=$scope.styleChange(selectFocusNode,"fontStyle");
									 endText="<span style='"+styleStr+"font-style:normal;'>"+selectFocusNode.textContent.substring(0,end)+"</span>";
								 }else{
									 var styleStr=$scope.styleChange(selectFocusNode,"fontStyle");
									 endText="<span style='"+styleStr+"font-style:italic;'>"+selectFocusNode.textContent.substring(0,end)+"</span>";
								 }
							 }else{
								 if($scope.currentFontStyle){
									 endText=selectFocusNode.textContent.substring(0,end);
								 }else{
									 endText="<span style='font-style:italic;'>"+selectFocusNode.textContent.substring(0,end)+"</span>";
								 }
								 
							 }
							 var centerText="";
								 for(var i=starNode+1;i<endNode;i++){
									 if(contentChild[i].tagName=="SPAN"&&contentChild[i].textContent==""){
									 		
									 }else if(contentChild[i].tagName=="BR"){
										 centerText=centerText+contentChild[i].outerHTML;
									 }else{
										 if(contentChild[i].length){
											 if($scope.currentFontStyle){
												 // contentChild[i].style.fontWeight="normal";
												 centerText=centerText+contentChild[i].textContent;
											 }else{
												 //contentChild[i].style.fontWeight="bold";
												 centerText=centerText+"<span style='font-style:italic'>"+contentChild[i].textContent+"</span>";
											 }
										 
										 }else{
											 if($scope.currentFontStyle){
												 contentChild[i].style.fontStyle="normal";
											 }else{
												 contentChild[i].style.fontStyle="italic";
											 }
											 centerText=centerText+contentChild[i].outerHTML;
										 }
									 }
								 }
								 $scope.allElements[$scope.checkedItemId].content = stringToStart + startA+startText+centerText+endText+endA + stringToEnd ;
								 $scope.urlFlag=true;
						 }
						 
						
						
					 } 
					 window.getSelection().removeAllRanges();
					 /*if($scope.allElements[$scope.checkedItemId].fontStyle==""){
						 $scope.allElements[$scope.checkedItemId].fontStyle="italic";
					 }else{
						 $scope.allElements[$scope.checkedItemId].fontStyle="";
					 }*/
				 };
				 
				 $scope.leaveFontStyle=function(){
					 $scope.addFontStyle=false;
				 };
				 
				 
				 
				
				 //下划线
				 $scope.textDecoration=function(){
					 var text=window.getSelection?window.getSelection().toString():(document.getSelection?document.getSelection():(document.selection?document.selection.createRange().text:""));
					 if(text!=""){
						 var contentChild=new Array();
						 if(window.getSelection().anchorNode.parentNode.tagName=="A"
							 ||window.getSelection().anchorNode.parentNode.tagName=="SPAN"){
							 contentChild=window.getSelection().anchorNode.parentNode.parentNode.childNodes;
						 }else{
							 contentChild=window.getSelection().anchorNode.parentNode.childNodes;
						 }
						 var star = window.getSelection().anchorOffset;
			             var end = window.getSelection().focusOffset;
						//ie浏览器，把起始点为最前面的，会获取为外面父节点
				        	if(window.getSelection().anchorNode.tagName=="P"
				        		||window.getSelection().anchorNode.tagName=="H1"
				        			||window.getSelection().anchorNode.tagName=="H2"||window.getSelection().anchorNode.tagName=="H3"){
				        		contentChild=window.getSelection().anchorNode.childNodes;
				        	}
						 var selectAnchorNode = window.getSelection().anchorNode;
			             if(window.getSelection().anchorNode.parentNode.tagName=="A"
			            	 ||window.getSelection().anchorNode.parentNode.tagName=="SPAN"){
			                selectAnchorNode = window.getSelection().anchorNode.parentNode;
			             }
			           //ie浏览器，把起始点为最前面的，会获取为外面父节点
				        	if((window.getSelection().anchorNode.tagName=="P"
				        		||window.getSelection().anchorNode.tagName=="H1"
				        			||window.getSelection().anchorNode.tagName=="H2"||window.getSelection().anchorNode.tagName=="H3")&&window.getSelection().anchorOffset==0){
				        		selectAnchorNode=contentChild[0];
				        		star=0;
				        	}
				        	//ie浏览器，把起始点为最前面的，会获取为外面父节点
				        	if((window.getSelection().anchorNode.tagName=="P"
				        		||window.getSelection().anchorNode.tagName=="H1"
				        			||window.getSelection().anchorNode.tagName=="H2"||window.getSelection().anchorNode.tagName=="H3")&&window.getSelection().anchorOffset!=0){
				        		selectAnchorNode=contentChild[contentChild.length-1];
				        		end=contentChild[contentChild.length-1].textContent.length;
				        	}
			             var selectFocusNode = window.getSelection().focusNode;
			             if(window.getSelection().focusNode.parentNode.tagName=="A"
			            	 ||window.getSelection().focusNode.parentNode.tagName=="SPAN"){
			                selectFocusNode = window.getSelection().focusNode.parentNode;
			             }
			           //ie浏览器，把结束点为最后面的，会获取为外面父节点
					        if((window.getSelection().focusNode.tagName=="P"
					        		||window.getSelection().focusNode.tagName=="H1"
					        			||window.getSelection().focusNode.tagName=="H2"||window.getSelection().focusNode.tagName=="H3")&&window.getSelection().focusOffset==0){
					        	selectFocusNode=contentChild[0];
					        	star=0;
					        }
					      //ie浏览器，把结束点为最后面的，会获取为外面父节点
					        if((window.getSelection().focusNode.tagName=="P"
					        		||window.getSelection().focusNode.tagName=="H1"
					        			||window.getSelection().focusNode.tagName=="H2"||window.getSelection().focusNode.tagName=="H3")&&window.getSelection().focusOffset!=0){
					        	selectFocusNode=contentChild[contentChild.length-1];
					        	end=contentChild[contentChild.length-1].textContent.length;
					        }
			             var starNode=0;
			             var endNode=0;
			             
						 for(var i=0;i<contentChild.length;i++){
							 if(selectAnchorNode==contentChild[i]){
								 starNode = i;
							 }
							 if(selectFocusNode==contentChild[i]){
								 endNode = i;
							 }
			              }
						 
						 if(starNode>endNode){
							 var t=endNode;
							 endNode=starNode;
							 starNode=t; 
							 var s=end;
							 end=star;
							 star=s;
							 var f=selectAnchorNode;
							 selectAnchorNode=selectFocusNode;
							 selectFocusNode=f;
						 }
						 
						 if(starNode==endNode&&star>end){
							 var s=end;
							 end=star;
							 star=s;
						 }
						 
						 //当选中的是同一块,没有样式的
						 if((starNode==endNode&&selectAnchorNode.tagName!="A")
								 &&(starNode==endNode&&selectAnchorNode.tagName!="SPAN")){
							 
							 var stringToStartText="";
							 for(var i=0;i<starNode;i++){
								 if(contentChild[i].tagName=="SPAN"&&contentChild[i].textContent==""){
								 		
								 }else if(contentChild[i].tagName=="BR"){
									 stringToStartText=stringToStartText+contentChild[i].outerHTML;
								 }else{
									 if(contentChild[i].length){
										 stringToStartText=stringToStartText+contentChild[i].textContent;
									 }else{
										 stringToStartText=stringToStartText+contentChild[i].outerHTML;
									 }
								 }
							 }
							 var stringToEndText="";
							 if(endNode!=(contentChild.length-1)){
								 for(var i=(endNode+1);i<contentChild.length;i++){
									 if(contentChild[i].tagName=="SPAN"&&contentChild[i].textContent==""){
									 		
									 }else if(contentChild[i].tagName=="BR"){
										 stringToEndText=stringToEndText+contentChild[i].outerHTML;
									 }else{
										 if(contentChild[i].length){
											 stringToEndText=stringToEndText+contentChild[i].textContent;
										 }else{
											 stringToEndText=stringToEndText+contentChild[i].outerHTML;
										 }
									 }
								 }
							 } 
							 var startText=window.getSelection().anchorNode.textContent.substring(0,star);
							 var endText=window.getSelection().focusNode.textContent.substring(end);
							 var centerText="<span style='text-decoration:underline;'>"+text+"</span>";
							 $scope.allElements[$scope.checkedItemId].content = stringToStartText+startText + centerText+endText+stringToEndText;
							 $scope.urlFlag=true;
							 return ;
						 }
						 
						 
						 
						 
						 var stringToStart="";
						 for(var i=0;i<starNode;i++){
							 if(contentChild[i].tagName=="SPAN"&&contentChild[i].textContent==""){
							 		
							 }else if(contentChild[i].tagName=="BR"){
								 stringToStart=stringToStart+contentChild[i].outerHTML;
							 }else{
								 if(contentChild[i].length){
								 
									 stringToStart=stringToStart+contentChild[i].textContent;
								 }else{
									 stringToStart=stringToStart+contentChild[i].outerHTML;
								 }
							 }
							 
						 }
						 var stringToEnd="";
						 if(endNode!=(contentChild.length-1)){
							 for(var i=(endNode+1);i<contentChild.length;i++){
								 if(contentChild[i].tagName=="SPAN"&&contentChild[i].textContent==""){
								 		
								 }else if(contentChild[i].tagName=="BR"){
									 stringToEnd=stringToEnd+contentChild[i].outerHTML;
								 }else{
									 if(contentChild[i].length){
										 stringToEnd=stringToEnd+contentChild[i].textContent;
									 }else{
										 stringToEnd=stringToEnd+contentChild[i].outerHTML;
									 }
								 }
							 }
						 }
						 var startA="";
						 if(selectAnchorNode.tagName=="A"){
							 if(star!=0){
								 if(selectAnchorNode.className.indexOf("inCode")>0){
									 var styleStr=$scope.styleStr(selectAnchorNode);
									 if(styleStr!=""){
										 startA="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
									 }else{
										 startA="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
									 }
									 
								 }else if(selectAnchorNode.className.indexOf("outCode")>0){
									 var styleStr=$scope.styleStr(selectAnchorNode);
									 if(styleStr!=""){
										 startA="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
									 }else{
										 startA="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
									 }
									 
								 }else{
									 var styleStr=$scope.styleStr(selectAnchorNode);
									 if(styleStr!=""){
										 startA="<a href='"+selectAnchorNode.href+"' style='"+styleStr+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
									 }else{
										 startA="<a href='"+selectAnchorNode.href+"'>"+selectAnchorNode.textContent.substring(0,star)+"</a>";
									 }
									 
								 }
								 
								 
							 }
						 }else if(selectAnchorNode.tagName=="SPAN"){
							 if(star!=0){
								 var styleStr=$scope.styleStr(selectAnchorNode);
								 if(styleStr!=""){
									 startA="<span style='"+styleStr+"'>"+selectAnchorNode.textContent.substring(0,star)+"</span>";
								 }else{
									 startA="<span>"+selectAnchorNode.textContent.substring(0,star)+"</span>";
								 }
								 
							 }
						 }else{
							 startA=selectAnchorNode.textContent.substring(0,star);
						 }
						 var endA="";
						 if(selectFocusNode.tagName=="A"){
							 if(end!=selectFocusNode.textContent.length){
								 if(selectFocusNode.className.indexOf("inCode")>0){
									 var styleStr=$scope.styleStr(selectFocusNode);
									 if(styleStr!=""){
										 endA="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"' style='"+styleStr+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
									 }else{
										 endA="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
									 }
									 
								 }else if(selectFocusNode.className.indexOf("outCode")>0){
									 var styleStr=$scope.styleStr(selectFocusNode);
									 if(styleStr!=""){
										 endA="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"' style='"+styleStr+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
									 }else{
										 endA="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
									 }
									 
								 }else{
									 var styleStr=$scope.styleStr(selectFocusNode);
									 if(styleStr!=""){
										 endA="<a href='"+selectFocusNode.href+"' style='"+styleStr+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
									 }else{
										 endA="<a href='"+selectFocusNode.href+"'>"+selectFocusNode.textContent.substring(end)+"</a>";
									 }
									 
								 }
								 
							 }
						 }else if(selectFocusNode.tagName=="SPAN"){
							 if(end!=selectFocusNode.textContent.length){
								 var styleStr=$scope.styleStr(selectFocusNode);
								 if(styleStr!=""){
									 endA="<span style='"+styleStr+"'>"+selectFocusNode.textContent.substring(end)+"</span>";
								 }else{
									 endA="<span>"+selectFocusNode.textContent.substring(end)+"</span>";
								 }
								 
							 }
						 }else{
							 endA=selectFocusNode.textContent.substring(end);
						 }
						 
						 if(starNode==endNode){
							 if(selectAnchorNode.tagName=="A"){
								 if($scope.currentTextDecoration){
									 var styleStr=$scope.styleChange(selectAnchorNode,"textDecoration");
									 text="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"text-decoration:none;'>"+text+"</a>";
								 }else{
									 var styleStr=$scope.styleChange(selectAnchorNode,"textDecoration");
									 text="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"text-decoration:underline;'>"+text+"</a>";
								 }
								 $scope.allElements[$scope.checkedItemId].content = stringToStart + startA+text+endA + stringToEnd ;
								 $scope.urlFlag=true;
							 }else if(selectAnchorNode.tagName=="SPAN"){
								 if($scope.currentTextDecoration){
									 var styleStr=$scope.styleChange(selectAnchorNode,"textDecoration");
									 text="<span style='"+styleStr+"text-decoration:none;'>"+text+"</span>";
								 }else{
									 var styleStr=$scope.styleChange(selectAnchorNode,"textDecoration");
									 text="<span style='"+styleStr+"text-decoration:underline;'>"+text+"</span>";
								 }
								 $scope.allElements[$scope.checkedItemId].content = stringToStart + startA+text+endA + stringToEnd ;
								 $scope.urlFlag=true;
							 }else{
								 text="<span style='text-decoration:underline;'>"+text+"</span>";
								 $scope.allElements[$scope.checkedItemId].content = stringToStart + startA+text+endA + stringToEnd ;
								 $scope.urlFlag=true;
							 }
							 
						 }else{
							 var startText="";
							 if(selectAnchorNode.tagName=="A"){
								 if($scope.currentTextDecoration){
									 var styleStr=$scope.styleChange(selectAnchorNode,"textDecoration");
									 startText="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"text-decoration:none;'>"+selectAnchorNode.textContent.substring(star)+"</a>";
								 }else{
									 var styleStr=$scope.styleChange(selectAnchorNode,"textDecoration");
									 startText="<a href='"+selectAnchorNode.href+"' class='"+selectAnchorNode.className+"' style='"+styleStr+"text-decoration:underline;'>"+selectAnchorNode.textContent.substring(star)+"</a>";
								 }
							 }else if(selectAnchorNode.tagName=="SPAN"){
								 if($scope.currentTextDecoration){
									 var styleStr=$scope.styleChange(selectAnchorNode,"textDecoration");
									 startText="<span style='"+styleStr+"text-decoration:none;'>"+selectAnchorNode.textContent.substring(star)+"</span>";
								 }else{
									 var styleStr=$scope.styleChange(selectAnchorNode,"textDecoration");
									 startText="<span style='"+styleStr+"text-decoration:underline;'>"+selectAnchorNode.textContent.substring(star)+"</span>";
								 }
							 }else{
								 if($scope.currentTextDecoration){
									 startText=selectAnchorNode.textContent.substring(star); 
								 }else{
									 startText="<span style='text-decoration:underline;'>"+selectAnchorNode.textContent.substring(star)+"</span>";
								 }
								 
							 }
							 
							 var endText="";
							 if(selectFocusNode.tagName=="A"){
								 if($scope.currentTextDecoration){
									 var styleStr=$scope.styleChange(selectFocusNode,"textDecoration");
									 endText="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"' style='"+styleStr+"text-decoration:none;'>"+selectFocusNode.textContent.substring(0,end)+"</a>";
								 }else{
									 var styleStr=$scope.styleChange(selectFocusNode,"textDecoration");
									 endText="<a href='"+selectFocusNode.href+"' class='"+selectFocusNode.className+"' style='"+styleStr+"text-decoration:underline;'>"+selectFocusNode.textContent.substring(0,end)+"</a>";
								 } 
								
							 }else if(selectFocusNode.tagName=="SPAN"){
								 if($scope.currentTextDecoration){
									 var styleStr=$scope.styleChange(selectFocusNode,"textDecoration");
									 endText="<span style='"+styleStr+"text-decoration:none;'>"+selectFocusNode.textContent.substring(0,end)+"</span>";
								 }else{
									 var styleStr=$scope.styleChange(selectFocusNode,"textDecoration");
									 endText="<span style='"+styleStr+"text-decoration:underline;'>"+selectFocusNode.textContent.substring(0,end)+"</span>";
								 } 
							 }else{
								 if($scope.currentTextDecoration){
									 endText=selectFocusNode.textContent.substring(0,end);
								 }else{
									 endText="<span style='text-decoration:underline;'>"+selectFocusNode.textContent.substring(0,end)+"</span>";
								 }
								 
							 }
							 var centerText="";
								 for(var i=starNode+1;i<endNode;i++){
									 if(contentChild[i].tagName=="SPAN"&&contentChild[i].textContent==""){
									 		
									 }else if(contentChild[i].tagName=="BR"){
										 centerText=centerText+contentChild[i].outerHTML;
									 }else{
										 if(contentChild[i].length){
											 if($scope.currentTextDecoration){
											
												 centerText=centerText+contentChild[i].textContent;
											 }else{
											
												 centerText=centerText+"<span style='text-decoration:underline;'>"+contentChild[i].textContent+"</span>";
											 }
										 
										 }else{
											 if($scope.currentTextDecoration){
												 contentChild[i].style.textDecoration="none";
											 }else{
												 contentChild[i].style.textDecoration="underline";
											 }
											 centerText=centerText+contentChild[i].outerHTML;
										 }
									 } 
								 }
								 $scope.allElements[$scope.checkedItemId].content = stringToStart + startA+startText+centerText+endText+endA + stringToEnd ;
								 $scope.urlFlag=true;
						 }
						 
						 
						
					 } 
					 window.getSelection().removeAllRanges();
					
				 };
				 
				 
				 $scope.updateElement=function(elementId){
					 if($scope.allElements[elementId].type=="image"){}
				 };
				 
				 
				 $scope.focusElement=function(ev,elementId){
					 $scope.checkedItemId=elementId;
					 $scope.clearCheck();
						getElementArr($scope);
						$scope.allElements[elementId].checked=true;
						//ev.preventDefault();
					};
				
				$scope.setParamFlag=false;
				//全局设置
				$scope.setParam=function(){
					$scope.setParamFlag=true;
					$scope.checkedItemId="";
					$scope.clearCheck();
					$scope.addTitleFlag=false;
					$scope.addFontStyle=false;
					$scope.addDocFlag=false;
					$scope.addMediaFlag=false;
				};
				
				$scope.getElementIndex=function(elementId,flag){
					for(var i=0;i<$scope.elementArr.length;i++){
						if($scope.elementArr[i].id==elementId){
							if(flag=="up"){
								if(i>0){
									return $scope.elementArr[i-1].id;
								}
							}else if(flag=="down"){
								if(i<($scope.elementArr.length-1)){
									return $scope.elementArr[i+1].id;
								}
							}
						}
					}
					return "";
				};
				
				
				
				$scope.goUp=function(){
					if($scope.checkedItemId!=null&& $scope.checkedItemId!="0"){
						
						var targetElementId=$scope.getElementIndex($scope.checkedItemId,"up");
						var allElements=new Array();
						if(targetElementId!=""){
							for(var item in $scope.allElements){
								var element=$scope.allElements[item];
								if(element.id==targetElementId){
									var felement=$scope.allElements[$scope.checkedItemId];
									allElements[felement.id]=felement;
								}else if(element.id==$scope.checkedItemId){
									var felement=$scope.allElements[targetElementId];
									allElements[felement.id]=felement;
								}else{
									allElements[element.id]=element;
								}
							}
							$scope.allElements=allElements;
						}
						getElementArr($scope);
						
					}
					
				};
				
				$scope.goDown=function(){
					if($scope.checkedItemId!=null&& $scope.checkedItemId!="0"){
						
						var targetElementId=$scope.getElementIndex($scope.checkedItemId,"down");
						var allElements=new Array();
						if(targetElementId!=""){
							for(var item in $scope.allElements){
								var element=$scope.allElements[item];
								if(element.id==targetElementId){
									var felement=$scope.allElements[$scope.checkedItemId];
									allElements[felement.id]=felement;
								}else if(element.id==$scope.checkedItemId){
									var felement=$scope.allElements[targetElementId];
									allElements[felement.id]=felement;
								}else{
									allElements[element.id]=element;
								}
							}
							$scope.allElements=allElements;
						}
						getElementArr($scope);
						
					}
					
				};
				
		})
	.directive('onFinishRenderFilters', function($timeout) {
	    return {
		restrict : 'A',
		link : function(scope, element, attr) {
		    if (scope.$last === true) {
			scope.$emit('ngRepeatFinished', element);
		    }
		}
	   };
	}).directive('contentEditable', function() {
	    return {
			restrict : 'A', // only activate on element attribute
			require : '?ngModel', // get a hold of NgModelController
			link : function(scope, element, attrs, ngModel) {
			    if (!ngModel) {
				return;
			    } // do nothing if no ng-model
			    // Specify how UI should be updated
			    ngModel.$render = function() {
				element.html(ngModel.$viewValue || '');
			    };
			    // Listen for change events to enable binding
			    try {
			        document.execCommand("AutoUrlDetect", false, false);
			    } catch (e) {}
			    element.on('paste', function(e) {
			        e.preventDefault();
			        var text = null;
			    
			        if(window.clipboardData && clipboardData.setData) {
			            // IE
			            text = window.clipboardData.getData('text');
			        } else {
			            text = (e.originalEvent || e).clipboardData.getData('text/plain') || prompt('在这里输入文本');
			        }
			        if (document.body.createTextRange) {    
			            if (document.selection) {
			                textRange = document.selection.createRange();
			            } else if (window.getSelection) {
			                sel = window.getSelection();
			                var range = sel.getRangeAt(0);
			                
			                // 创建临时元素，使得TextRange可以移动到正确的位置
			                var tempEl = document.createElement("span");
			                tempEl.innerHTML = "&#FEFF;";
			                range.deleteContents();
			                range.insertNode(tempEl);
			                textRange = document.body.createTextRange();
			                textRange.moveToElementText(tempEl);
			                tempEl.parentNode.removeChild(tempEl);
			            }
			            text=text.replace(/\r\n/g,"");
			            text=text.replace(/\n/g,"");
			            textRange.text = text;
			            textRange.collapse(false);
			            textRange.select();
			        } else {
			            // Chrome之类浏览器
			        	text=text.replace(/\r\n/g,"");
			        	text=text.replace(/\n/g,"");
			            document.execCommand("insertText", false, text);
			        }
			    });
			    /*if (window.navigator.userAgent.indexOf("MSIE") >= 1) {*/
			    	element.on('keydown',function(e){
				    	var ev = e || window.event;
						var key = ev.keyCode || ev.charCode;
						if(key == 13) {
					        if (document.body.createTextRange) {  
					        	e.preventDefault();
						        var text = "<br/>";
					            if (document.selection) {
					                textRange = document.selection.createRange();
					            } else if (window.getSelection) {
					                sel = window.getSelection();
					                var range = sel.getRangeAt(0);
					                
					                // 创建临时元素，使得TextRange可以移动到正确的位置
					                var tempEl = document.createElement("span");
					                tempEl.innerHTML = "&#FEFF;";
					                range.deleteContents();
					                range.insertNode(tempEl);
					                textRange = document.body.createTextRange();
					                textRange.moveToElementText(tempEl);
					                tempEl.parentNode.removeChild(tempEl);
					            }
					            textRange.pasteHTML(text);
					            textRange.collapse(false);
					            textRange.select();
					        } else {
					            // Chrome之类浏览器
					           // document.execCommand("InsertParagraph", false, text);
					        }
						}
				    });
			    /*}*/
			    
			    element.on('keyup change ', function() {
			    	/*if(scope.urlFlag){
			    		scope.urlFlag=false;
			    	}else{*/
			    		scope.$apply(readViewText);
			    	//}
			    	
			    });
			    
			    
			    function readViewText() {
				var html = element.html();
				// When we clear the content editable the browser leaves
				// a <br> behind
				// If strip-br attribute is provided then we strip this
				// out
				if (attrs.stripBr && html === '<br>') {
				    html = '';
				}
				ngModel.$setViewValue(html);
			    }

			    // No need to initialize, AngularJS will initialize the text
			    // based on ng-model attribute
			    // Write data to the model

			}
		    };
		});


function getElementArr($scope){
	   $scope.elementArr=[];
		for(var item in $scope.allElements){
			delete $scope.allElements[item]["$$hashKey"];
			$scope.elementArr.push($scope.allElements[item]);
		}
};

function allowDrop(ev)
{
ev.preventDefault();
}

function drag(ev)
{
ev.dataTransfer.setData("Text",ev.target.parentElement.id);

}

function drop(ev)
{
	var allElements=new Array();
	if(ev.target.parentElement.id!=""&&ev.dataTransfer.getData("Text")!=""){
		for(var item in fsjd.allElements){
			var element=fsjd.allElements[item];
			if(element.id==ev.target.parentElement.id){
				var felement=fsjd.allElements[ev.dataTransfer.getData("Text")];
				allElements[felement.id]=felement;
			}else if(element.id==ev.dataTransfer.getData("Text")){
				var felement=fsjd.allElements[ev.target.parentElement.id];
				allElements[felement.id]=felement;
			}else{
				allElements[element.id]=element;
			}
		}
		fsjd.allElements=allElements;
	}
	getElementArr(fsjd);
	ev.target.click();
	ev.preventDefault();
}


function loadUrlPage($scope,$http){
	if(window.localStorage){
		var storage = window.localStorage;
		if(storage.getItem('urlHtml')){
			var responseData=storage.getItem('urlHtml');
			var obj=$scope.compile(responseData)($scope);
        	$('#moadContent').html(obj);
           //$('#urlModal').modal('show');
            $('#urlModal').modal({
    	     	show:true,
    		   backdrop:'static'
    	   });
            return;
		}
	}
	$http.get('addUrlPage.html').success(function(responseData){
        if(null!=responseData && responseData!=''){
        	if (responseData.code == 911) {
		    	alert("session过期，请重新登录！");
		    	location.href='index.jsp';
		    }
        	if(window.localStorage){
        		window.localStorage.setItem('urlHtml',responseData);
        	}
        	var obj=$scope.compile(responseData)($scope);
        	$('#moadContent').html(obj);
            //$('#urlModal').modal('show');
            $('#urlModal').modal({
    	     	show:true,
    		   backdrop:'static'
    	   });
            
        }
    });
}


function loadImageUpload($scope,$http){
	if(window.localStorage){
		var storage = window.localStorage;
		if(storage.getItem('imageHtml')){
			var responseData=storage.getItem('imageHtml');
			var obj=$scope.compile(responseData)($scope);
        	$('#moadContent').html(obj);
        	$('#imageModal').modal({
        	     	show:true,
        		   backdrop:'static'
        	   });
           
            return;
		}
	}
	$http.get('addImagePage.html').success(function(responseData){
        if(null!=responseData && responseData!=''){
        	if (responseData.code == 911) {
		    	alert("session过期，请重新登录！");
		    	location.href='index.jsp';
		    }
        	if(window.localStorage){
        		window.localStorage.setItem('imageHtml',responseData);
        	}
        	var obj=$scope.compile(responseData)($scope);
        	$('#moadContent').html(obj);
        	$('#imageModal').modal({
    	     	show:true,
    		   backdrop:'static'
    	   });
       
        }
    });
}


function loadVideoUpload($scope,$http){
	if(window.localStorage){
		var storage = window.localStorage;
		if(storage.getItem('videoHtml')){
			var responseData=storage.getItem('videoHtml');
			var obj=$scope.compile(responseData)($scope);
        	$('#moadContent').html(obj);
           
            $('#videoModal').modal({
    	     	show:true,
    		   backdrop:'static'
    	   });
            return;
		}
	}
	$http.get('addVideoPage.html').success(function(responseData){
        if(null!=responseData && responseData!=''){
        	if (responseData.code == 911) {
		    	alert("session过期，请重新登录！");
		    	location.href='index.jsp';
		    }
        	if(window.localStorage){
        		window.localStorage.setItem('videoHtml',responseData);
        	}
        	var obj=$scope.compile(responseData)($scope);
        	$('#moadContent').html(obj);
            
            $('#videoModal').modal({
    	     	show:true,
    		   backdrop:'static'
    	   });
        }
    });
}

function loadAudioUpload($scope,$http){
	if(window.localStorage){
		var storage = window.localStorage;
		if(storage.getItem('audioHtml')){
			var responseData=storage.getItem('audioHtml');
			var obj=$scope.compile(responseData)($scope);
        	$('#moadContent').html(obj);
            //$('#audioModal').modal('show');
            $('#audioModal').modal({
    	     	show:true,
    		   backdrop:'static'
    	   });
            return;
		}
	}
	$http.get('addAudioPage.html').success(function(responseData){
        if(null!=responseData && responseData!=''){
        	if (responseData.code == 911) {
		    	alert("session过期，请重新登录！");
		    	location.href='index.jsp';
		    }
        	if(window.localStorage){
        		window.localStorage.setItem('audioHtml',responseData);
        	}
        	var obj=$scope.compile(responseData)($scope);
        	$('#moadContent').html(obj);
            
            $('#audioModal').modal({
    	     	show:true,
    		   backdrop:'static'
    	   });
        }
    });
}

function loadPdfUpload($scope,$http){
	if(window.localStorage){
		var storage = window.localStorage;
		if(storage.getItem('pdfHtml')){
			var responseData=storage.getItem('pdfHtml');
			var obj=$scope.compile(responseData)($scope);
        	$('#moadContent').html(obj);
           
            $('#pdfModal').modal({
    	     	show:true,
    		   backdrop:'static'
    	   });
            return;
		}
	}
	$http.get('addPdfPage.html').success(function(responseData){
        if(null!=responseData && responseData!=''){
        	if (responseData.code == 911) {
		    	alert("session过期，请重新登录！");
		    	location.href='index.jsp';
		    }
        	if(window.localStorage){
        		window.localStorage.setItem('pdfHtml',responseData);
        	}
        	var obj=$scope.compile(responseData)($scope);
        	$('#moadContent').html(obj);
            
            $('#pdfModal').modal({
    	     	show:true,
    		   backdrop:'static'
    	   });
        }
    });
}

function loadWordUpload($scope,$http){
	if(window.localStorage){
		var storage = window.localStorage;
		if(storage.getItem('wordHtml')){
			var responseData=storage.getItem('wordHtml');
			var obj=$scope.compile(responseData)($scope);
        	$('#moadContent').html(obj);
           
            $('#wordModal').modal({
    	     	show:true,
    		   backdrop:'static'
    	   });
            return;
		}
	}
	$http.get('addWordPage.html').success(function(responseData){
        if(null!=responseData && responseData!=''){
        	if (responseData.code == 911) {
		    	alert("session过期，请重新登录！");
		    	location.href='index.jsp';
		    }
        	if(window.localStorage){
        		window.localStorage.setItem('wordHtml',responseData);
        	}
        	var obj=$scope.compile(responseData)($scope);
        	$('#moadContent').html(obj);
            
            $('#wordModal').modal({
    	     	show:true,
    		   backdrop:'static'
    	   });
        }
    });
}
function loadOtherUpload($scope,$http){
	if(window.localStorage){
		var storage = window.localStorage;
		if(storage.getItem('otherHtml')){
			var responseData=storage.getItem('otherHtml');
			var obj=$scope.compile(responseData)($scope);
        	$('#moadContent').html(obj);
           
            $('#otherModal').modal({
    	     	show:true,
    		   backdrop:'static'
    	   });
            return;
		}
	}
	$http.get('addOtherPage.html').success(function(responseData){
        if(null!=responseData && responseData!=''){
        	if (responseData.code == 911) {
		    	alert("session过期，请重新登录！");
		    	location.href='index.jsp';
		    }
        	if(window.localStorage){
        		window.localStorage.setItem('otherHtml',responseData);
        	}
        	var obj=$scope.compile(responseData)($scope);
        	$('#moadContent').html(obj);
            
            $('#otherModal').modal({
    	     	show:true,
    		   backdrop:'static'
    	   });
        }
    });
}

function loadResource($scope,$http){
            $('#resourceModal').modal({
    	     	show:true,
    		   backdrop:'static',
    		   remote:fsjd.path+ '/resPackage/resource/main'
    	   });   
}


function addSource(data){
	var dataJson=eval( "(" + data+ ")" );
	for(var i=0;i<dataJson.length;i++){
		var obj=dataJson[i];
		if(obj.type=="image"){
			var imageUrls=[];
			var image={path:obj.path,title:obj.title,href:"",hrefType:"No",hrefNodeId:""};
			imageUrls.push(image);
			obj.imagesUrl=imageUrls;
			fsjd.$apply(fsjd.saveResourceImage(obj));
		}else if(obj.type=="audio"){
			fsjd.$apply(fsjd.saveResourceAudio(obj));
		}else if(obj.type=="video"){
			fsjd.$apply(fsjd.saveResourceVideo(obj));
		}else if(obj.type=="word"){
			fsjd.$apply(fsjd.saveResourceWord(obj));
		}else if(obj.type=="pdf"){
			fsjd.$apply(fsjd.saveResourcePdf(obj));
		}else if(obj.type=="accessory"){
			fsjd.$apply(fsjd.saveResourceOther(obj));
		}else if(obj.type=="eContent"){
			fsjd.$apply(fsjd.addResourceContent(obj));
		}
	}
	$("#resourceModal").hide();
	$(".modal-backdrop").remove();
	$(".modal-content").html("");
	return;
}

function closeResource(){
	$("#resourceModal").hide();
	$(".modal-backdrop").remove();
	$(".modal-content").html("");
}


//Firefox, Google Chrome, Opera, Safari, Internet Explorer from version 9
function OnInput(flag,index){
	if(flag){
		
		fsjd.allElements[fsjd.checkedItemId].imagesSrc[index].hrefType="No";
	}else{
		fsjd.currentPic.imagesUrl[index].hrefType="No";
	}
	
	
};


//Internet Explorer
function OnPropChanged(flag,index){
	if(flag){
		if (event.propertyName.toLowerCase () == "value") {
			
			fsjd.allElements[fsjd.checkedItemId].imagesSrc[index].hrefType="No";
	    }
	}else{
		if (event.propertyName.toLowerCase () == "value") {
			fsjd.currentPic.imagesUrl[index].hrefType="No";
	    }
	}
	
};

function fontColorEvent(e){
	e.preventDefault();
	$('#fontColor').click();
}

function fontBgColorEvent(e){
	e.preventDefault();
	$('#fontBgColor').click();
}
function closePanel(){
	$("#colorpanel").hide();
}
